From a43290192beedc6335efc3841c05ec7fa54e8871 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 30 Mar 2019 17:51:26 -0700 Subject: [PATCH] [serialize] Add packed_map --- src/hb-map.hh | 7 +++++++ src/hb-serialize.hh | 24 +++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index 341c159..a176ccd 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -96,6 +96,13 @@ struct hb_hashmap_t fini_shallow (); } + void reset () + { + /* TODO Keep array? */ + fini_shallow (); + init_shallow (); + } + bool in_error () const { return !successful; } bool resize () diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 86f802a..6911e92 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -31,6 +31,7 @@ #include "hb.hh" #include "hb-blob.hh" +#include "hb-map.hh" /* @@ -80,9 +81,10 @@ struct hb_serialize_context_t this->tail = this->end; this->debug_depth = 0; + this->current.resize (0); this->packed.resize (0); this->packed.push ()->bytes.arrayZ = this->end; - this->current.resize (0); + this->packed_map.reset (); } bool propagate_error (bool e) @@ -132,6 +134,19 @@ struct hb_serialize_context_t } objidx_t pop_pack () { + snapshot_t snap = current.pop (); + + char *s = snap.head; + char *e = head; + unsigned l = e - s; + + tail -= l; + memmove (tail, s, l); + + /* TODO... */ + packed.push (); + + head = snap.head; return 0; } @@ -258,11 +273,14 @@ struct hb_serialize_context_t private: + /* Stack of currently under construction object locations. */ + hb_vector_t current; + /* Stack of packed objects. Object 0 is always nil object. */ hb_vector_t packed; - /* Stack of currently under construction object locations. */ - hb_vector_t current; + /* Map view of packed objects. */ + hb_hashmap_t packed_map; }; -- 2.7.4