From 7fd82283263f8caded4870d6e12f74c7e660fa8d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 30 Mar 2019 19:16:20 -0700 Subject: [PATCH] [serialize] Towards maintaining hashmap --- src/hb-algs.hh | 2 +- src/hb-serialize.hh | 16 ++++++++++++++-- src/hb-vector.hh | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 128e49036..ab6782de3 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -45,7 +45,7 @@ static const struct template uint32_t operator () (const T *v) const - { return hb_hash (v); } + { return operator() (v); } template diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 617928815..e7873ab69 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -51,6 +51,14 @@ struct hb_serialize_context_t { 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 { bool wide: 1; @@ -155,13 +163,17 @@ struct hb_serialize_context_t obj.head = tail; obj.tail = tail + len; - packed.push (hb_move (obj)); + object_t *key = packed.push (hb_move (obj)); /* TODO Handle error. */ if (unlikely (packed.in_error ())) return 0; - return packed.length - 1; + objidx_t objidx = packed.length - 1; + + packed_map.set (key, objidx); + + return objidx; } void revert (range_t snap) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index f68943987..2a92a892e 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -122,6 +122,7 @@ struct hb_vector_t const Type& tail () const { return (*this)[length - 1]; } explicit operator bool () const { return length; } + unsigned get_size () const { return length * item_size; } /* Sink interface. */ template