diff --git a/src/graph/graph.hh b/src/graph/graph.hh index 0d3dae2c0..3479e002c 100644 --- a/src/graph/graph.hh +++ b/src/graph/graph.hh @@ -49,6 +49,21 @@ struct graph_t unsigned end = 0; unsigned priority = 0; + bool equals (vertex_t& other, graph_t& graph) + { + if (as_bytes () != other.as_bytes ()) + return false; + + obj.real_links.qsort (); + other.obj.real_links.qsort (); + return links_equal (graph, obj.real_links, other.obj.real_links); + } + + hb_bytes_t as_bytes () + { + return hb_bytes_t (obj.head, table_size ()); + } + friend void swap (vertex_t& a, vertex_t& b) { hb_swap (a.obj, b.obj); @@ -167,6 +182,39 @@ struct graph_t return -table_size; } + + private: + bool links_equal (graph_t& graph, + const hb_vector_t& this_links, + const hb_vector_t& other_links) const + { + auto a = this_links.iter (); + auto b = other_links.iter (); + + while (a && b) + { + const auto& link_a = *a; + const auto& link_b = *b; + + if (link_a.width != link_b.width || + link_a.is_signed != link_b.is_signed || + link_a.whence != link_b.whence || + link_a.position != link_b.position || + link_a.bias != link_b.bias) + return false; + + if (!graph.vertices_[link_a.objidx].equals (graph.vertices_[link_b.objidx], graph)) + return false; + + a++; + b++; + } + + if (bool (a) != bool (b)) + return false; + + return true; + } }; template @@ -233,6 +281,11 @@ struct graph_t hb_free (b); } + bool operator== (graph_t& other) + { + return vertices_[root_idx ()].equals (other.vertices_[other.root_idx ()], *this); + } + bool in_error () const { return !successful || diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 4b22e46a5..f47cde5eb 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -142,7 +142,10 @@ struct hb_serialize_context_t HB_INTERNAL static int cmp (const void* a, const void* b) { - return ((const link_t*)a)->position - ((const link_t*)b)->position; + int cmp = ((const link_t*)a)->position - ((const link_t*)b)->position; + if (cmp) return cmp; + + return ((const link_t*)a)->objidx - ((const link_t*)b)->objidx; } };