Browse Source

base: remove Array::PushFirst() because Array::Insert(..., 0) works just

as well, remove PushUniqueFirst in favour of InsertUnique(), and optimise
Array::Swap().
undefined
Sam Hocevar 10 years ago
parent
commit
1e23be81a0
2 changed files with 22 additions and 33 deletions
  1. +2
    -0
      src/image/image.cpp
  2. +20
    -33
      src/lol/base/array.h

+ 2
- 0
src/image/image.cpp View File

@@ -15,6 +15,8 @@
#include "core.h" #include "core.h"
#include "image-private.h" #include "image-private.h"


#include <algorithm> /* for std::swap */

namespace lol namespace lol
{ {




+ 20
- 33
src/lol/base/array.h View File

@@ -13,7 +13,7 @@
// The Array class // The Array class
// --------------- // ---------------
// A very simple Array class not unlike the std::vector, with some nice // A very simple Array class not unlike the std::vector, with some nice
// additional features, eg. Array<int,float> for automatic arrays of structs.
// additional features, eg. Array<int,float> for automatic arrays of tuples.
// //


#if !defined __LOL_BASE_ARRAY_H__ #if !defined __LOL_BASE_ARRAY_H__
@@ -21,7 +21,8 @@


#include <lol/base/assert.h> #include <lol/base/assert.h>


#include <new>
#include <new> /* for placement new */
#include <algorithm> /* for std::swap */
#include <stdint.h> #include <stdint.h>


namespace lol namespace lol
@@ -216,33 +217,11 @@ public:


inline bool PushUnique(T const &x) inline bool PushUnique(T const &x)
{ {
int idx = Find(x);
if (idx == INDEX_NONE)
{
Push(x);
return true;
}
return false;
}
if (Find(x) != INDEX_NONE)
return false;


//PushFirst, insert, etc : CRUDE VERSION
inline void PushFirst(T const &x)
{
ArrayBase<T, ARRAY> tmp;
tmp.Push(x);
tmp += *this;
*this = tmp;
}

inline bool PushUniqueFirst(T const &x)
{
int idx = Find(x);
if (idx == INDEX_NONE)
{
PushFirst(x);
return true;
}
return false;
Push(x);
return true;
} }


inline void Insert(T const &x, int pos) inline void Insert(T const &x, int pos)
@@ -262,6 +241,18 @@ public:
++m_count; ++m_count;
} }


inline bool InsertUnique(T const &x, int pos)
{
ASSERT(pos >= 0);
ASSERT(pos <= m_count);

if (Find(x) != INDEX_NONE)
return false;

Insert(x, pos);
return true;
}

inline int Find(T const &x) inline int Find(T const &x)
{ {
for (int i = 0; i < m_count; ++i) for (int i = 0; i < m_count; ++i)
@@ -320,11 +311,7 @@ public:
ASSERT(pos2 < m_count); ASSERT(pos2 < m_count);


if (pos1 != pos2) if (pos1 != pos2)
{
Element tmp = (*this)[pos1];
(*this)[pos1] = (*this)[pos2];
(*this)[pos2] = tmp;
}
std::swap((*this)[pos1], (*this)[pos2]);
} }


void Remove(int pos, int todelete = 1) void Remove(int pos, int todelete = 1)


Loading…
Cancel
Save