[set/map/vector] Make constructable, but not copy or assignable
Disable copy/assign on them, as they shouldn't. Make constructor / destructor call init_shallow/fini_shallow, and make those idempotent. So, these three can be constructed on stack now and no init/fini call is needed. As such, hb_auto_t<> is not needed anymore. I'll remove that separately.
This commit is contained in:
parent
ea0e51d1b1
commit
67a22f377d
|
@ -44,6 +44,10 @@ inline uint32_t Hash (const T &v)
|
||||||
|
|
||||||
struct hb_map_t
|
struct hb_map_t
|
||||||
{
|
{
|
||||||
|
HB_NO_COPY_ASSIGN (hb_map_t);
|
||||||
|
inline hb_map_t (void) { init_shallow (); }
|
||||||
|
inline ~hb_map_t (void) { fini_shallow (); }
|
||||||
|
|
||||||
struct item_t
|
struct item_t
|
||||||
{
|
{
|
||||||
hb_codepoint_t key;
|
hb_codepoint_t key;
|
||||||
|
@ -77,9 +81,11 @@ struct hb_map_t
|
||||||
inline void fini_shallow (void)
|
inline void fini_shallow (void)
|
||||||
{
|
{
|
||||||
free (items);
|
free (items);
|
||||||
|
items = nullptr;
|
||||||
}
|
}
|
||||||
inline void fini (void)
|
inline void fini (void)
|
||||||
{
|
{
|
||||||
|
population = occupancy = 0;
|
||||||
hb_object_fini (this);
|
hb_object_fini (this);
|
||||||
fini_shallow ();
|
fini_shallow ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,10 @@
|
||||||
|
|
||||||
struct hb_set_t
|
struct hb_set_t
|
||||||
{
|
{
|
||||||
|
HB_NO_COPY_ASSIGN (hb_set_t);
|
||||||
|
inline hb_set_t (void) { init_shallow (); }
|
||||||
|
inline ~hb_set_t (void) { fini_shallow (); }
|
||||||
|
|
||||||
struct page_map_t
|
struct page_map_t
|
||||||
{
|
{
|
||||||
inline int cmp (const page_map_t *o) const { return (int) o->major - (int) major; }
|
inline int cmp (const page_map_t *o) const { return (int) o->major - (int) major; }
|
||||||
|
@ -199,6 +203,7 @@ struct hb_set_t
|
||||||
}
|
}
|
||||||
inline void fini_shallow (void)
|
inline void fini_shallow (void)
|
||||||
{
|
{
|
||||||
|
population = 0;
|
||||||
page_map.fini ();
|
page_map.fini ();
|
||||||
pages.fini ();
|
pages.fini ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,10 @@
|
||||||
template <typename Type, unsigned int StaticSize=8>
|
template <typename Type, unsigned int StaticSize=8>
|
||||||
struct hb_vector_t
|
struct hb_vector_t
|
||||||
{
|
{
|
||||||
|
HB_NO_COPY_ASSIGN_TEMPLATE2 (hb_vector_t, Type, StaticSize);
|
||||||
|
inline hb_vector_t (void) { init (); }
|
||||||
|
inline ~hb_vector_t (void) { fini (); }
|
||||||
|
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
private:
|
private:
|
||||||
unsigned int allocated; /* == 0 means allocation failed. */
|
unsigned int allocated; /* == 0 means allocation failed. */
|
||||||
|
@ -48,6 +52,22 @@ struct hb_vector_t
|
||||||
arrayZ_ = nullptr;
|
arrayZ_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void fini (void)
|
||||||
|
{
|
||||||
|
if (arrayZ_)
|
||||||
|
free (arrayZ_);
|
||||||
|
arrayZ_ = nullptr;
|
||||||
|
allocated = len = 0;
|
||||||
|
}
|
||||||
|
inline void fini_deep (void)
|
||||||
|
{
|
||||||
|
Type *array = arrayZ();
|
||||||
|
unsigned int count = len;
|
||||||
|
for (unsigned int i = 0; i < count; i++)
|
||||||
|
array[i].fini ();
|
||||||
|
fini ();
|
||||||
|
}
|
||||||
|
|
||||||
inline Type * arrayZ (void)
|
inline Type * arrayZ (void)
|
||||||
{ return arrayZ_ ? arrayZ_ : static_array; }
|
{ return arrayZ_ ? arrayZ_ : static_array; }
|
||||||
inline const Type * arrayZ (void) const
|
inline const Type * arrayZ (void) const
|
||||||
|
@ -255,23 +275,6 @@ struct hb_vector_t
|
||||||
*i = max;
|
*i = max;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void fini_deep (void)
|
|
||||||
{
|
|
||||||
Type *array = arrayZ();
|
|
||||||
unsigned int count = len;
|
|
||||||
for (unsigned int i = 0; i < count; i++)
|
|
||||||
array[i].fini ();
|
|
||||||
fini ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void fini (void)
|
|
||||||
{
|
|
||||||
if (arrayZ_)
|
|
||||||
free (arrayZ_);
|
|
||||||
arrayZ_ = nullptr;
|
|
||||||
allocated = len = 0;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
12
src/hb.hh
12
src/hb.hh
|
@ -339,6 +339,16 @@ static_assert ((sizeof (hb_var_int_t) == 4), "");
|
||||||
|
|
||||||
#if __cplusplus >= 201103L
|
#if __cplusplus >= 201103L
|
||||||
|
|
||||||
|
/* We only enable these with C++11 or later, since earlier language
|
||||||
|
* does not allow structs with constructors in unions, and we need
|
||||||
|
* those. */
|
||||||
|
|
||||||
|
#define HB_NO_COPY_ASSIGN(TypeName) \
|
||||||
|
TypeName(const TypeName&); \
|
||||||
|
void operator=(const TypeName&)
|
||||||
|
#define HB_NO_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2) \
|
||||||
|
TypeName(const TypeName<T1, T2>&); \
|
||||||
|
void operator=(const TypeName<T1, T2>&)
|
||||||
#define HB_NO_CREATE_COPY_ASSIGN(TypeName) \
|
#define HB_NO_CREATE_COPY_ASSIGN(TypeName) \
|
||||||
TypeName(void); \
|
TypeName(void); \
|
||||||
TypeName(const TypeName&); \
|
TypeName(const TypeName&); \
|
||||||
|
@ -354,6 +364,8 @@ static_assert ((sizeof (hb_var_int_t) == 4), "");
|
||||||
|
|
||||||
#else /* __cpluspplus >= 201103L */
|
#else /* __cpluspplus >= 201103L */
|
||||||
|
|
||||||
|
#define HB_NO_COPY_ASSIGN(TypeName)
|
||||||
|
#define HB_NO_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2)
|
||||||
#define HB_NO_CREATE_COPY_ASSIGN(TypeName)
|
#define HB_NO_CREATE_COPY_ASSIGN(TypeName)
|
||||||
#define HB_NO_CREATE_COPY_ASSIGN_TEMPLATE(TypeName, T)
|
#define HB_NO_CREATE_COPY_ASSIGN_TEMPLATE(TypeName, T)
|
||||||
#define HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2)
|
#define HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2(TypeName, T1, T2)
|
||||||
|
|
Loading…
Reference in New Issue