Kaynağa Gözat

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 yıl önce
ebeveyn
işleme
1e23be81a0
2 değiştirilmiş dosya ile 22 ekleme ve 33 silme
  1. +2
    -0
      src/image/image.cpp
  2. +20
    -33
      src/lol/base/array.h

+ 2
- 0
src/image/image.cpp Dosyayı Görüntüle

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

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

namespace lol
{



+ 20
- 33
src/lol/base/array.h Dosyayı Görüntüle

@@ -13,7 +13,7 @@
// The Array class
// ---------------
// 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__
@@ -21,7 +21,8 @@

#include <lol/base/assert.h>

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

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

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)
@@ -262,6 +241,18 @@ public:
++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)
{
for (int i = 0; i < m_count; ++i)
@@ -320,11 +311,7 @@ public:
ASSERT(pos2 < m_count);

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)


Yükleniyor…
İptal
Kaydet