提交 7fd82283 编写于 作者: B Behdad Esfahbod

[serialize] Towards maintaining hashmap

上级 f254f45a
...@@ -45,7 +45,7 @@ static const struct ...@@ -45,7 +45,7 @@ static const struct
template <typename T> template <typename T>
uint32_t operator () (const T *v) const uint32_t operator () (const T *v) const
{ return hb_hash (v); } { return operator() (v); }
template <typename T, template <typename T,
hb_enable_if (hb_is_integer (T))> hb_enable_if (hb_is_integer (T))>
......
...@@ -51,6 +51,14 @@ struct hb_serialize_context_t ...@@ -51,6 +51,14 @@ struct hb_serialize_context_t
{ {
void fini () { links.fini (); } void fini () { links.fini (); }
bool operator == (const object_t &o) const
{
return (tail - head == o.tail - o.head)
&& (links.length != o.links.length)
&& 0 == memcmp (head, o.head, tail - head)
&& 0 == memcmp (&links, &o.links, links.get_size ());
}
struct link_t struct link_t
{ {
bool wide: 1; bool wide: 1;
...@@ -155,13 +163,17 @@ struct hb_serialize_context_t ...@@ -155,13 +163,17 @@ struct hb_serialize_context_t
obj.head = tail; obj.head = tail;
obj.tail = tail + len; obj.tail = tail + len;
packed.push (hb_move (obj)); object_t *key = packed.push (hb_move (obj));
/* TODO Handle error. */ /* TODO Handle error. */
if (unlikely (packed.in_error ())) if (unlikely (packed.in_error ()))
return 0; return 0;
return packed.length - 1; objidx_t objidx = packed.length - 1;
packed_map.set (key, objidx);
return objidx;
} }
void revert (range_t snap) void revert (range_t snap)
......
...@@ -122,6 +122,7 @@ struct hb_vector_t ...@@ -122,6 +122,7 @@ struct hb_vector_t
const Type& tail () const { return (*this)[length - 1]; } const Type& tail () const { return (*this)[length - 1]; }
explicit operator bool () const { return length; } explicit operator bool () const { return length; }
unsigned get_size () const { return length * item_size; }
/* Sink interface. */ /* Sink interface. */
template <typename T> template <typename T>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册