[vector] Simplify arrayZ

Was turned into function when we had static ones and wanted to be
move-safe...  Not the case anymore.
This commit is contained in:
Behdad Esfahbod 2019-05-10 18:40:29 -07:00
parent 4d67743ffd
commit 2fb3a8327a
4 changed files with 39 additions and 46 deletions

View File

@ -598,7 +598,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan,
} else {
active_feature_t *feature = active_features.find (&event->feature);
if (feature)
active_features.remove (feature - active_features.arrayZ ());
active_features.remove (feature - active_features.arrayZ);
}
}
}

View File

@ -167,7 +167,7 @@ struct CFFIndex
byteArray.resize (buffArray.length);
for (unsigned int i = 0; i < byteArray.length; i++)
{
byteArray[i] = byte_str_t (buffArray[i].arrayZ (), buffArray[i].length);
byteArray[i] = byte_str_t (buffArray[i].arrayZ, buffArray[i].length);
}
bool result = this->serialize (c, offSize_, byteArray);
byteArray.fini ();

View File

@ -698,7 +698,7 @@ _hb_uniscribe_shape (hb_shape_plan_t *shape_plan,
{
active_feature_t *feature = active_features.find (&event->feature);
if (feature)
active_features.remove (feature - active_features.arrayZ ());
active_features.remove (feature - active_features.arrayZ);
}
}
@ -889,8 +889,8 @@ retry:
&items[i].a,
script_tags[i],
language_tag,
range_char_counts.arrayZ (),
range_properties.arrayZ (),
range_char_counts.arrayZ,
range_properties.arrayZ,
range_properties.length,
pchars + chars_offset,
item_chars_len,
@ -930,8 +930,8 @@ retry:
&items[i].a,
script_tags[i],
language_tag,
range_char_counts.arrayZ (),
range_properties.arrayZ (),
range_char_counts.arrayZ,
range_properties.arrayZ,
range_properties.length,
pchars + chars_offset,
log_clusters + chars_offset,

View File

@ -49,35 +49,34 @@ struct hb_vector_t
{
allocated = o.allocated;
length = o.length;
arrayZ_ = o.arrayZ_;
arrayZ = o.arrayZ;
o.init ();
}
~hb_vector_t () { fini (); }
unsigned int length;
private:
int allocated; /* == -1 means allocation failed. */
Type *arrayZ_;
public:
unsigned int length;
public:
Type *arrayZ;
void init ()
{
allocated = length = 0;
arrayZ_ = nullptr;
arrayZ = nullptr;
}
void fini ()
{
if (arrayZ_)
free (arrayZ_);
free (arrayZ);
init ();
}
void fini_deep ()
{
Type *array = arrayZ();
unsigned int count = length;
for (unsigned int i = 0; i < count; i++)
array[i].fini ();
arrayZ[i].fini ();
fini ();
}
@ -95,33 +94,30 @@ struct hb_vector_t
fini ();
allocated = o.allocated;
length = o.length;
arrayZ_ = o.arrayZ_;
arrayZ = o.arrayZ;
o.init ();
return *this;
}
hb_bytes_t as_bytes () const
{ return hb_bytes_t ((const char *) arrayZ(), length * item_size); }
{ return hb_bytes_t ((const char *) arrayZ, length * item_size); }
bool operator == (const hb_vector_t &o) const { return as_array () == o.as_array (); }
uint32_t hash () const { return as_array ().hash (); }
const Type * arrayZ () const { return arrayZ_; }
Type * arrayZ () { return arrayZ_; }
Type& operator [] (int i_)
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= length))
return Crap (Type);
return arrayZ()[i];
return arrayZ[i];
}
const Type& operator [] (int i_) const
{
unsigned int i = (unsigned int) i_;
if (unlikely (i >= length))
return Null(Type);
return arrayZ()[i];
return arrayZ[i];
}
Type& tail () { return (*this)[length - 1]; }
@ -134,8 +130,8 @@ struct hb_vector_t
template <typename T>
hb_vector_t& operator << (T&& v) { push (hb_forward<T> (v)); return *this; }
hb_array_t< Type> as_array () { return hb_array (arrayZ(), length); }
hb_array_t<const Type> as_array () const { return hb_array (arrayZ(), length); }
hb_array_t< Type> as_array () { return hb_array (arrayZ, length); }
hb_array_t<const Type> as_array () const { return hb_array (arrayZ, length); }
/* Iterator. */
typedef hb_array_t<const Type> iter_t;
@ -155,21 +151,21 @@ struct hb_vector_t
{ return as_array ().sub_array (start_offset, count);}
hb_sorted_array_t<Type> as_sorted_array ()
{ return hb_sorted_array (arrayZ(), length); }
{ return hb_sorted_array (arrayZ, length); }
hb_sorted_array_t<const Type> as_sorted_array () const
{ return hb_sorted_array (arrayZ(), length); }
{ return hb_sorted_array (arrayZ, length); }
template <typename T> explicit operator T * () { return arrayZ(); }
template <typename T> explicit operator const T * () const { return arrayZ(); }
template <typename T> explicit operator T * () { return arrayZ; }
template <typename T> explicit operator const T * () const { return arrayZ; }
Type * operator + (unsigned int i) { return arrayZ() + i; }
const Type * operator + (unsigned int i) const { return arrayZ() + i; }
Type * operator + (unsigned int i) { return arrayZ + i; }
const Type * operator + (unsigned int i) const { return arrayZ + i; }
Type *push ()
{
if (unlikely (!resize (length + 1)))
return &Crap(Type);
return &arrayZ()[length - 1];
return &arrayZ[length - 1];
}
template <typename T>
Type *push (T&& v)
@ -202,7 +198,7 @@ struct hb_vector_t
(new_allocated < (unsigned) allocated) ||
hb_unsigned_mul_overflows (new_allocated, sizeof (Type));
if (likely (!overflows))
new_array = (Type *) realloc (arrayZ_, new_allocated * sizeof (Type));
new_array = (Type *) realloc (arrayZ, new_allocated * sizeof (Type));
if (unlikely (!new_array))
{
@ -210,7 +206,7 @@ struct hb_vector_t
return false;
}
arrayZ_ = new_array;
arrayZ = new_array;
allocated = new_allocated;
return true;
@ -223,7 +219,7 @@ struct hb_vector_t
return false;
if (size > length)
memset (arrayZ() + length, 0, (size - length) * sizeof (*arrayZ()));
memset (arrayZ + length, 0, (size - length) * sizeof (*arrayZ));
length = size;
return true;
@ -232,16 +228,15 @@ struct hb_vector_t
Type pop ()
{
if (!length) return Null(Type);
return hb_move (arrayZ()[--length]); /* Does this move actually work? */
return hb_move (arrayZ[--length]); /* Does this move actually work? */
}
void remove (unsigned int i)
{
if (unlikely (i >= length))
return;
Type *array = arrayZ();
memmove (static_cast<void *> (&array[i]),
static_cast<void *> (&array[i + 1]),
memmove (static_cast<void *> (&arrayZ[i]),
static_cast<void *> (&arrayZ[i + 1]),
(length - i - 1) * sizeof (Type));
length--;
}
@ -256,19 +251,17 @@ struct hb_vector_t
template <typename T>
Type *find (T v)
{
Type *array = arrayZ();
for (unsigned int i = 0; i < length; i++)
if (array[i] == v)
return &array[i];
if (arrayZ[i] == v)
return &arrayZ[i];
return nullptr;
}
template <typename T>
const Type *find (T v) const
{
const Type *array = arrayZ();
for (unsigned int i = 0; i < length; i++)
if (array[i] == v)
return &array[i];
if (arrayZ[i] == v)
return &arrayZ[i];
return nullptr;
}
@ -288,8 +281,8 @@ struct hb_vector_t
template <typename Type>
struct hb_sorted_vector_t : hb_vector_t<Type>
{
hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ(), this->length); }
hb_sorted_array_t<const Type> as_array () const { return hb_sorted_array (this->arrayZ(), this->length); }
hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ, this->length); }
hb_sorted_array_t<const Type> as_array () const { return hb_sorted_array (this->arrayZ, this->length); }
/* Iterator. */
typedef hb_sorted_array_t<const Type> const_iter_t;