From eeda2c549ddd103ebf8f9d1e20ae30137f5ed532 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 18:36:57 -0600 Subject: [PATCH 01/32] [vector] Add initializer_list constructor & tests --- src/hb-vector.hh | 15 +++++++++++++-- src/test-algs.cc | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 44c174d07..d3a5dffac 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -31,6 +31,8 @@ #include "hb-array.hh" #include "hb-null.hh" +#include + template struct hb_vector_t @@ -39,9 +41,14 @@ struct hb_vector_t static constexpr unsigned item_size = hb_static_size (Type); hb_vector_t () { init (); } - hb_vector_t (const hb_vector_t &o) + hb_vector_t (std::initializer_list l) : hb_vector_t () + { + alloc (l.size ()); + for (auto&& i : l) + push (i); + } + hb_vector_t (const hb_vector_t &o) : hb_vector_t () { - init (); alloc (o.length); hb_copy (o, *this); } @@ -302,6 +309,10 @@ struct hb_vector_t template struct hb_sorted_vector_t : hb_vector_t { + hb_sorted_vector_t () : hb_vector_t () {} + hb_sorted_vector_t (std::initializer_list l) : hb_vector_t (l) {} + hb_sorted_vector_t (hb_sorted_vector_t& o) : hb_vector_t (o) {} + hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ, this->length); } hb_sorted_array_t as_array () const { return hb_sorted_array (this->arrayZ, this->length); } diff --git a/src/test-algs.cc b/src/test-algs.cc index f8b8ff666..0f6b1fbd0 100644 --- a/src/test-algs.cc +++ b/src/test-algs.cc @@ -91,5 +91,25 @@ main (int argc, char **argv) assert (++hb_inc (x) == 3); assert (x == 3); + { + hb_vector_t v1 {1, 2, 3}; + hb_vector_t v2 {4, 5}; + hb_swap (v1, v2); + assert (v1.length == 2); + assert (v1[0] == 4); + assert (v2.length == 3); + assert (v2[2] == 3); + } + + { + hb_sorted_vector_t v1 {1, 2, 3}; + hb_sorted_vector_t v2 {4, 5}; + hb_swap (v1, v2); + assert (v1.length == 2); + assert (v1[0] == 4); + assert (v2.length == 3); + assert (v2[2] == 3); + } + return 0; } From 18a078f968072990cc50f96d4b6e47b32a6001c5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 20:06:58 -0600 Subject: [PATCH 02/32] [vector] Implement move assignment using swap --- src/hb-vector.hh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index d3a5dffac..af07c28be 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -110,11 +110,7 @@ struct hb_vector_t } hb_vector_t& operator = (hb_vector_t &&o) { - fini (); - allocated = o.allocated; - length = o.length; - arrayZ = o.arrayZ; - o.init (); + hb_swap (*this, o); return *this; } From ee75e716c1fec110e9ee2d30be9db14b75515404 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 20:18:49 -0600 Subject: [PATCH 03/32] [vector] Add initializer from iterable --- src/hb-vector.hh | 6 ++++++ src/test-algs.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index af07c28be..92c74dc13 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -47,6 +47,12 @@ struct hb_vector_t for (auto&& i : l) push (i); } + template + hb_vector_t (const Iterable &o) : hb_vector_t () + { + hb_copy (o, *this); + } hb_vector_t (const hb_vector_t &o) : hb_vector_t () { alloc (o.length); diff --git a/src/test-algs.cc b/src/test-algs.cc index 0f6b1fbd0..fd69b51c3 100644 --- a/src/test-algs.cc +++ b/src/test-algs.cc @@ -26,6 +26,7 @@ #include "hb.hh" #include "hb-algs.hh" +#include "hb-set.hh" static char * @@ -91,6 +92,35 @@ main (int argc, char **argv) assert (++hb_inc (x) == 3); assert (x == 3); + /* Test initializing vector from iterable. */ + { + hb_set_t s; + + s.add (18); + s.add (12); + + hb_vector_t v (s); + + assert (v.length == 2); + assert (v[0] == 12); + assert (v[1] == 18); + } + + /* Test initializing vector from iterator. */ + { + hb_set_t s; + + s.add (18); + s.add (12); + + hb_vector_t v (hb_iter (s)); + + assert (v.length == 2); + assert (v[0] == 12); + assert (v[1] == 18); + } + + /* Test initializing vector from initializer list and swapping. */ { hb_vector_t v1 {1, 2, 3}; hb_vector_t v2 {4, 5}; @@ -101,6 +131,7 @@ main (int argc, char **argv) assert (v2[2] == 3); } + /* Test initializing sorted-vector from initializer list and swapping. */ { hb_sorted_vector_t v1 {1, 2, 3}; hb_sorted_vector_t v2 {4, 5}; From 11135150a7e9955aefbf9ac943367a618b513981 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 20:23:12 -0600 Subject: [PATCH 04/32] [vector] Move test code into separate file --- src/Makefile.am | 14 +++++++- src/meson.build | 1 + src/test-algs.cc | 51 ---------------------------- src/test-vector.cc | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 52 deletions(-) create mode 100644 src/test-vector.cc diff --git a/src/Makefile.am b/src/Makefile.am index f405331d6..bdd7568af 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -342,7 +342,19 @@ test_gsub_would_substitute_SOURCES = test-gsub-would-substitute.cc test_gsub_would_substitute_CPPFLAGS = $(HBCFLAGS) $(FREETYPE_CFLAGS) test_gsub_would_substitute_LDADD = libharfbuzz.la $(HBLIBS) $(FREETYPE_LIBS) -COMPILED_TESTS = test-algs test-array test-iter test-meta test-number test-ot-tag test-priority-queue test-unicode-ranges test-bimap test-repacker +COMPILED_TESTS = \ + test-algs \ + test-array \ + test-iter \ + test-meta \ + test-number \ + test-ot-tag \ + test-priority-queue \ + test-unicode-ranges \ + test-vector \ + test-bimap \ + test-repacker \ + $(NULL) COMPILED_TESTS_CPPFLAGS = $(HBCFLAGS) -DMAIN -UNDEBUG COMPILED_TESTS_LDADD = libharfbuzz.la $(HBLIBS) check_PROGRAMS += $(COMPILED_TESTS) diff --git a/src/meson.build b/src/meson.build index db4208f5c..8209fb50c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -492,6 +492,7 @@ if get_option('tests').enabled() 'test-number': ['test-number.cc', 'hb-number.cc'], 'test-ot-tag': ['hb-ot-tag.cc'], 'test-unicode-ranges': ['test-unicode-ranges.cc'], + 'test-vector': ['test-vector.cc', 'hb-static.cc'], 'test-bimap': ['test-bimap.cc', 'hb-static.cc'], } foreach name, source : compiled_tests diff --git a/src/test-algs.cc b/src/test-algs.cc index fd69b51c3..f8b8ff666 100644 --- a/src/test-algs.cc +++ b/src/test-algs.cc @@ -26,7 +26,6 @@ #include "hb.hh" #include "hb-algs.hh" -#include "hb-set.hh" static char * @@ -92,55 +91,5 @@ main (int argc, char **argv) assert (++hb_inc (x) == 3); assert (x == 3); - /* Test initializing vector from iterable. */ - { - hb_set_t s; - - s.add (18); - s.add (12); - - hb_vector_t v (s); - - assert (v.length == 2); - assert (v[0] == 12); - assert (v[1] == 18); - } - - /* Test initializing vector from iterator. */ - { - hb_set_t s; - - s.add (18); - s.add (12); - - hb_vector_t v (hb_iter (s)); - - assert (v.length == 2); - assert (v[0] == 12); - assert (v[1] == 18); - } - - /* Test initializing vector from initializer list and swapping. */ - { - hb_vector_t v1 {1, 2, 3}; - hb_vector_t v2 {4, 5}; - hb_swap (v1, v2); - assert (v1.length == 2); - assert (v1[0] == 4); - assert (v2.length == 3); - assert (v2[2] == 3); - } - - /* Test initializing sorted-vector from initializer list and swapping. */ - { - hb_sorted_vector_t v1 {1, 2, 3}; - hb_sorted_vector_t v2 {4, 5}; - hb_swap (v1, v2); - assert (v1.length == 2); - assert (v1[0] == 4); - assert (v2.length == 3); - assert (v2[2] == 3); - } - return 0; } diff --git a/src/test-vector.cc b/src/test-vector.cc new file mode 100644 index 000000000..80bea6b76 --- /dev/null +++ b/src/test-vector.cc @@ -0,0 +1,85 @@ +/* + * Copyright © 2021 Behdad Esfahbod + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + */ + +#include "hb.hh" +#include "hb-vector.hh" +#include "hb-set.hh" + + +int +main (int argc, char **argv) +{ + /* Test initializing vector from iterable. */ + { + hb_set_t s; + + s.add (18); + s.add (12); + + hb_vector_t v (s); + + assert (v.length == 2); + assert (v[0] == 12); + assert (v[1] == 18); + } + + /* Test initializing vector from iterator. */ + { + hb_set_t s; + + s.add (18); + s.add (12); + + hb_vector_t v (hb_iter (s)); + + assert (v.length == 2); + assert (v[0] == 12); + assert (v[1] == 18); + } + + /* Test initializing vector from initializer list and swapping. */ + { + hb_vector_t v1 {1, 2, 3}; + hb_vector_t v2 {4, 5}; + hb_swap (v1, v2); + assert (v1.length == 2); + assert (v1[0] == 4); + assert (v2.length == 3); + assert (v2[2] == 3); + } + + /* Test initializing sorted-vector from initializer list and swapping. */ + { + hb_sorted_vector_t v1 {1, 2, 3}; + hb_sorted_vector_t v2 {4, 5}; + hb_swap (v1, v2); + assert (v1.length == 2); + assert (v1[0] == 4); + assert (v2.length == 3); + assert (v2[2] == 3); + } + + return 0; +} From f15858be5f09a9fdfbec9ccc68490e23e5db35ad Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 20:26:07 -0600 Subject: [PATCH 05/32] [vector] Pre-allocate if iterator has random-access length --- src/hb-vector.hh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 92c74dc13..acd66a7fc 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -51,6 +51,8 @@ struct hb_vector_t hb_requires (hb_is_iterable (Iterable))> hb_vector_t (const Iterable &o) : hb_vector_t () { + if (hb_iter (o).is_random_access_iterator) + alloc (hb_len (hb_iter (o))); hb_copy (o, *this); } hb_vector_t (const hb_vector_t &o) : hb_vector_t () From 628a0f3796992fe858b368c8b6358ef9d83a21e1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 20:36:55 -0600 Subject: [PATCH 06/32] [vector] Add more tests --- src/test-vector.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/test-vector.cc b/src/test-vector.cc index 80bea6b76..1aeb86bdd 100644 --- a/src/test-vector.cc +++ b/src/test-vector.cc @@ -31,6 +31,47 @@ int main (int argc, char **argv) { + + /* Test copy constructor. */ + { + hb_vector_t v1 {1, 2}; + hb_vector_t v2 {v1}; + assert (v1.length == 2); + assert (v1[0] == 1); + assert (v1[1] == 2); + assert (v2.length == 2); + assert (v2[0] == 1); + assert (v2[1] == 2); + } + + /* Test copy assignment. */ + { + hb_vector_t v1 {1, 2}; + hb_vector_t v2 = v1; + assert (v1.length == 2); + assert (v1[0] == 1); + assert (v1[1] == 2); + assert (v2.length == 2); + assert (v2[0] == 1); + assert (v2[1] == 2); + } + + /* Test move constructor. */ + { + hb_vector_t v {hb_vector_t {1, 2}}; + assert (v.length == 2); + assert (v[0] == 1); + assert (v[1] == 2); + } + + /* Test move assignment. */ + { + hb_vector_t v; + v = hb_vector_t {1, 2}; + assert (v.length == 2); + assert (v[0] == 1); + assert (v[1] == 2); + } /* Test initializing vector from iterable. */ { hb_set_t s; From dcd18da611436455733e3a80075d07685a6f96f7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 20:55:30 -0600 Subject: [PATCH 07/32] [set] Add standard the 5 standard methods & tests --- src/Makefile.am | 9 +++++ src/hb-set.hh | 33 ++++++++++++++--- src/meson.build | 1 + src/test-set.cc | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 src/test-set.cc diff --git a/src/Makefile.am b/src/Makefile.am index bdd7568af..bd88fa05a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -350,6 +350,7 @@ COMPILED_TESTS = \ test-number \ test-ot-tag \ test-priority-queue \ + test-set \ test-unicode-ranges \ test-vector \ test-bimap \ @@ -392,10 +393,18 @@ test_ot_tag_SOURCES = hb-ot-tag.cc test_ot_tag_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) test_ot_tag_LDADD = $(COMPILED_TESTS_LDADD) +test_set_SOURCES = test-set.cc hb-static.cc +test_set_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) +test_set_LDADD = $(COMPILED_TESTS_LDADD) + test_unicode_ranges_SOURCES = test-unicode-ranges.cc test_unicode_ranges_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) test_unicode_ranges_LDADD = $(COMPILED_TESTS_LDADD) +test_vector_SOURCES = test-vector.cc hb-static.cc +test_vector_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) +test_vector_LDADD = $(COMPILED_TESTS_LDADD) + test_bimap_SOURCES = test-bimap.cc hb-static.cc test_bimap_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) test_bimap_LDADD = $(COMPILED_TESTS_LDADD) diff --git a/src/hb-set.hh b/src/hb-set.hh index 437e23436..17eb8adf4 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -31,6 +31,8 @@ #include "hb.hh" #include "hb-bit-set-invertible.hh" +#include + template struct hb_sparseset_t @@ -42,9 +44,22 @@ struct hb_sparseset_t ~hb_sparseset_t () { fini (); } hb_sparseset_t (const hb_sparseset_t& other) : hb_sparseset_t () { set (other); } - void operator= (const hb_sparseset_t& other) { set (other); } - // TODO Add move construtor/assign - // TODO Add constructor for Iterator + hb_sparseset_t (hb_sparseset_t&& other) : hb_sparseset_t () { s = hb_move (other.s); } + hb_sparseset_t& operator= (const hb_sparseset_t& other) { set (other); return *this; } + hb_sparseset_t& operator= (hb_sparseset_t&& other) { hb_swap (*this, other); return *this; } + friend void swap (hb_sparseset_t& a, hb_sparseset_t& b) { hb_swap (a.s, b.s); } + + hb_sparseset_t (std::initializer_list l) : hb_sparseset_t () + { + for (auto&& i : l) + add (i); + } + template + hb_sparseset_t (const Iterable &o) : hb_sparseset_t () + { + hb_copy (o, *this); + } void init_shallow () { s.init (); } void init () @@ -140,7 +155,17 @@ struct hb_sparseset_t operator iter_t () const { return iter (); } }; -struct hb_set_t : hb_sparseset_t {}; +struct hb_set_t : hb_sparseset_t +{ + hb_set_t () : hb_sparseset_t () {} + hb_set_t (std::initializer_list l) : hb_sparseset_t (l) {} + hb_set_t (hb_set_t& o) : hb_sparseset_t (o) {} + template + hb_set_t (const Iterable &o) : hb_sparseset_t (o) {} + hb_set_t& operator= (const hb_set_t& other) { hb_sparseset_t::operator= (other); return *this; } + hb_set_t& operator= (hb_set_t&& other) { hb_sparseset_t::operator= (hb_move (other)); return *this; } +}; static_assert (hb_set_t::INVALID == HB_SET_VALUE_INVALID, ""); diff --git a/src/meson.build b/src/meson.build index 8209fb50c..ca40176ab 100644 --- a/src/meson.build +++ b/src/meson.build @@ -491,6 +491,7 @@ if get_option('tests').enabled() 'test-meta': ['test-meta.cc', 'hb-static.cc'], 'test-number': ['test-number.cc', 'hb-number.cc'], 'test-ot-tag': ['hb-ot-tag.cc'], + 'test-set': ['test-set.cc', 'hb-static.cc'], 'test-unicode-ranges': ['test-unicode-ranges.cc'], 'test-vector': ['test-vector.cc', 'hb-static.cc'], 'test-bimap': ['test-bimap.cc', 'hb-static.cc'], diff --git a/src/test-set.cc b/src/test-set.cc new file mode 100644 index 000000000..531df175a --- /dev/null +++ b/src/test-set.cc @@ -0,0 +1,96 @@ +/* + * Copyright © 2021 Behdad Esfahbod + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + */ + +#include "hb.hh" +#include "hb-set.hh" + + +int +main (int argc, char **argv) +{ + + /* Test copy constructor. */ + { + hb_set_t v1 {1, 2}; + hb_set_t v2 {v1}; + assert (v1.get_population () == 2); + assert (v2.get_population () == 2); + } + + /* Test copy assignment. */ + { + hb_set_t v1 {1, 2}; + hb_set_t v2 = v1; + assert (v1.get_population () == 2); + assert (v2.get_population () == 2); + } + + /* Test move constructor. */ + { + hb_set_t v {hb_set_t {1, 2}}; + assert (v.get_population () == 2); + } + + /* Test move assignment. */ + { + hb_set_t v; + v = hb_set_t {1, 2}; + assert (v.get_population () == 2); + } + /* Test initializing set from iterable. */ + { + hb_set_t s; + + s.add (18); + s.add (12); + + hb_set_t v (s); + + assert (v.get_population () == 2); + } + + /* Test initializing set from iterator. */ + { + hb_set_t s; + + s.add (18); + s.add (12); + + hb_set_t v (hb_iter (s)); + + assert (v.get_population () == 2); + } + + /* Test initializing set from initializer list and swapping. */ + { + hb_set_t v1 {1, 2, 3}; + hb_set_t v2 {4, 5}; + hb_swap (v1, v2); + assert (v1.get_population () == 2); + assert (v2.get_population () == 3); + } + + return 0; +} From 11eadb5d2886c8d2a6eef26866f080bde9ff65ce Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 21:07:09 -0600 Subject: [PATCH 08/32] [bit-set-invertible] Implement standard-5 methods & swap --- src/hb-bit-set-invertible.hh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/hb-bit-set-invertible.hh b/src/hb-bit-set-invertible.hh index f48b72fe6..978d589ab 100644 --- a/src/hb-bit-set-invertible.hh +++ b/src/hb-bit-set-invertible.hh @@ -35,10 +35,18 @@ struct hb_bit_set_invertible_t { hb_bit_set_t s; - bool inverted; + bool inverted = false; - hb_bit_set_invertible_t () { init (); } - ~hb_bit_set_invertible_t () { fini (); } + hb_bit_set_invertible_t () = default; + hb_bit_set_invertible_t (hb_bit_set_invertible_t& o) = default; + hb_bit_set_invertible_t (hb_bit_set_invertible_t&& o) = default; + hb_bit_set_invertible_t& operator= (const hb_bit_set_invertible_t& o) = default; + hb_bit_set_invertible_t& operator= (hb_bit_set_invertible_t&& o) = default; + friend void swap (hb_bit_set_invertible_t &a, hb_bit_set_invertible_t &b) + { + hb_swap (a.inverted, b.inverted); + hb_swap (a.s, b.s); + } void init () { s.init (); inverted = false; } void fini () { s.fini (); } From 1e3f57c07904578079a58e37baf3a6bb01c0be0c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 21:14:12 -0600 Subject: [PATCH 09/32] [bit-set] Implement standard-5 methods plus swap --- src/hb-bit-set.hh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index c21778d88..9f76e81ce 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -35,13 +35,21 @@ struct hb_bit_set_t { - hb_bit_set_t () { init (); } - ~hb_bit_set_t () { fini (); } + hb_bit_set_t () = default; + ~hb_bit_set_t () = default; hb_bit_set_t (const hb_bit_set_t& other) : hb_bit_set_t () { set (other); } - void operator= (const hb_bit_set_t& other) { set (other); } - // TODO Add move construtor/assign - // TODO Add constructor for Iterator; with specialization for (sorted) vector / array? + hb_bit_set_t ( hb_bit_set_t&& other) : hb_bit_set_t () { hb_swap (*this, other); } + hb_bit_set_t& operator= (const hb_bit_set_t& other) { set (other); return *this; } + hb_bit_set_t& operator= (hb_bit_set_t&& other) { hb_swap (*this, other); return *this; } + friend void swap (hb_bit_set_t &a, hb_bit_set_t &b) + { + hb_swap (a.successful, b.successful); + hb_swap (a.population, b.population); + hb_swap (a.last_page_lookup, b.last_page_lookup); + hb_swap (a.page_map, b.page_map); + hb_swap (a.pages, b.pages); + } void init () { @@ -67,9 +75,9 @@ struct hb_bit_set_t uint32_t index; }; - bool successful; /* Allocations successful */ - mutable unsigned int population; - mutable unsigned int last_page_lookup; + bool successful = true; /* Allocations successful */ + mutable unsigned int population = 0; + mutable unsigned int last_page_lookup = 0; hb_sorted_vector_t page_map; hb_vector_t pages; From b6c0b40fc2a66893c70f02dc20f2c99b0a996b6a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 21:15:38 -0600 Subject: [PATCH 10/32] [vector] Use default constructor --- src/hb-vector.hh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index acd66a7fc..108aa09f7 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -40,7 +40,7 @@ struct hb_vector_t typedef Type item_t; static constexpr unsigned item_size = hb_static_size (Type); - hb_vector_t () { init (); } + hb_vector_t () = default; hb_vector_t (std::initializer_list l) : hb_vector_t () { alloc (l.size ()); @@ -70,11 +70,11 @@ struct hb_vector_t ~hb_vector_t () { fini (); } private: - int allocated; /* == -1 means allocation failed. */ + int allocated = 0; /* == -1 means allocation failed. */ public: - unsigned int length; + unsigned int length = 0; public: - Type *arrayZ; + Type *arrayZ = nullptr; void init () { From 34fa5e290146b14ee6bdb261811d219fd7711574 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 21:25:03 -0600 Subject: [PATCH 11/32] [set] More default operators --- src/hb-set.hh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hb-set.hh b/src/hb-set.hh index 17eb8adf4..a1a09d3c3 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -157,14 +157,15 @@ struct hb_sparseset_t struct hb_set_t : hb_sparseset_t { - hb_set_t () : hb_sparseset_t () {} + hb_set_t () = default; + ~hb_set_t () = default; + hb_set_t (hb_set_t& o) = default; + hb_set_t& operator= (const hb_set_t& other) = default; + hb_set_t& operator= (hb_set_t&& other) = default; hb_set_t (std::initializer_list l) : hb_sparseset_t (l) {} - hb_set_t (hb_set_t& o) : hb_sparseset_t (o) {} template hb_set_t (const Iterable &o) : hb_sparseset_t (o) {} - hb_set_t& operator= (const hb_set_t& other) { hb_sparseset_t::operator= (other); return *this; } - hb_set_t& operator= (hb_set_t&& other) { hb_sparseset_t::operator= (hb_move (other)); return *this; } }; static_assert (hb_set_t::INVALID == HB_SET_VALUE_INVALID, ""); From e97e79967e6ed0dd5719c2b88cf72f8860790245 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 21:34:46 -0600 Subject: [PATCH 12/32] Verbiage --- src/hb-set.hh | 8 ++++---- src/hb-vector.hh | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hb-set.hh b/src/hb-set.hh index a1a09d3c3..58188b516 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -49,10 +49,10 @@ struct hb_sparseset_t hb_sparseset_t& operator= (hb_sparseset_t&& other) { hb_swap (*this, other); return *this; } friend void swap (hb_sparseset_t& a, hb_sparseset_t& b) { hb_swap (a.s, b.s); } - hb_sparseset_t (std::initializer_list l) : hb_sparseset_t () + hb_sparseset_t (std::initializer_list lst) : hb_sparseset_t () { - for (auto&& i : l) - add (i); + for (auto&& item : lst) + add (item); } template @@ -162,7 +162,7 @@ struct hb_set_t : hb_sparseset_t hb_set_t (hb_set_t& o) = default; hb_set_t& operator= (const hb_set_t& other) = default; hb_set_t& operator= (hb_set_t&& other) = default; - hb_set_t (std::initializer_list l) : hb_sparseset_t (l) {} + hb_set_t (std::initializer_list lst) : hb_sparseset_t (lst) {} template hb_set_t (const Iterable &o) : hb_sparseset_t (o) {} diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 108aa09f7..286b79f73 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -41,11 +41,11 @@ struct hb_vector_t static constexpr unsigned item_size = hb_static_size (Type); hb_vector_t () = default; - hb_vector_t (std::initializer_list l) : hb_vector_t () + hb_vector_t (std::initializer_list lst) : hb_vector_t () { - alloc (l.size ()); - for (auto&& i : l) - push (i); + alloc (lst.size ()); + for (auto&& item : lst) + push (item); } template @@ -314,7 +314,7 @@ template struct hb_sorted_vector_t : hb_vector_t { hb_sorted_vector_t () : hb_vector_t () {} - hb_sorted_vector_t (std::initializer_list l) : hb_vector_t (l) {} + hb_sorted_vector_t (std::initializer_list lst) : hb_vector_t (lst) {} hb_sorted_vector_t (hb_sorted_vector_t& o) : hb_vector_t (o) {} hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ, this->length); } From a28b5d03b5c86d2ffc352ef35463718aa4a00a9f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 21:43:44 -0600 Subject: [PATCH 13/32] [vector] Add swap() friend to hb_sorted_vector_t --- src/hb-vector.hh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 286b79f73..43e21d498 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -316,6 +316,8 @@ struct hb_sorted_vector_t : hb_vector_t hb_sorted_vector_t () : hb_vector_t () {} hb_sorted_vector_t (std::initializer_list lst) : hb_vector_t (lst) {} hb_sorted_vector_t (hb_sorted_vector_t& o) : hb_vector_t (o) {} + friend void swap (hb_sorted_vector_t& a, hb_sorted_vector_t& b) + { hb_swap ((hb_vector_t&) (a), (hb_vector_t&) (b)); } hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ, this->length); } hb_sorted_array_t as_array () const { return hb_sorted_array (this->arrayZ, this->length); } From 6f74d80ed1f20a31744f78ee5a290b76b1dfb102 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 21:49:32 -0600 Subject: [PATCH 14/32] [vector] Complete sorted_vector 5-methods --- src/hb-vector.hh | 11 +++++++++-- src/test-vector.cc | 19 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/hb-vector.hh b/src/hb-vector.hh index 43e21d498..c34498bbc 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -313,9 +313,16 @@ struct hb_vector_t template struct hb_sorted_vector_t : hb_vector_t { - hb_sorted_vector_t () : hb_vector_t () {} + hb_sorted_vector_t () = default; + ~hb_sorted_vector_t () = default; + hb_sorted_vector_t (hb_sorted_vector_t& o) = default; + hb_sorted_vector_t (hb_sorted_vector_t &&o) = default; hb_sorted_vector_t (std::initializer_list lst) : hb_vector_t (lst) {} - hb_sorted_vector_t (hb_sorted_vector_t& o) : hb_vector_t (o) {} + template + hb_sorted_vector_t (const Iterable &o) : hb_vector_t (o) {} + hb_sorted_vector_t& operator = (const hb_sorted_vector_t &o) = default; + hb_sorted_vector_t& operator = (hb_sorted_vector_t &&o) = default; friend void swap (hb_sorted_vector_t& a, hb_sorted_vector_t& b) { hb_swap ((hb_vector_t&) (a), (hb_vector_t&) (b)); } diff --git a/src/test-vector.cc b/src/test-vector.cc index 1aeb86bdd..7dacec818 100644 --- a/src/test-vector.cc +++ b/src/test-vector.cc @@ -36,6 +36,7 @@ main (int argc, char **argv) { hb_vector_t v1 {1, 2}; hb_vector_t v2 {v1}; + hb_vector_t V2 {v1}; assert (v1.length == 2); assert (v1[0] == 1); assert (v1[1] == 2); @@ -48,6 +49,7 @@ main (int argc, char **argv) { hb_vector_t v1 {1, 2}; hb_vector_t v2 = v1; + hb_vector_t V2 = v1; assert (v1.length == 2); assert (v1[0] == 1); assert (v1[1] == 2); @@ -59,6 +61,7 @@ main (int argc, char **argv) /* Test move constructor. */ { hb_vector_t v {hb_vector_t {1, 2}}; + hb_vector_t V {hb_vector_t {1, 2}}; assert (v.length == 2); assert (v[0] == 1); assert (v[1] == 2); @@ -67,12 +70,14 @@ main (int argc, char **argv) /* Test move assignment. */ { hb_vector_t v; + hb_sorted_vector_t V; v = hb_vector_t {1, 2}; + V = hb_sorted_vector_t {1, 2}; assert (v.length == 2); assert (v[0] == 1); assert (v[1] == 2); } - /* Test initializing vector from iterable. */ + /* Test initializing from iterable. */ { hb_set_t s; @@ -80,13 +85,17 @@ main (int argc, char **argv) s.add (12); hb_vector_t v (s); + hb_sorted_vector_t V (s); assert (v.length == 2); + assert (V.length == 2); assert (v[0] == 12); + assert (V[0] == 12); assert (v[1] == 18); + assert (V[1] == 18); } - /* Test initializing vector from iterator. */ + /* Test initializing from iterator. */ { hb_set_t s; @@ -94,13 +103,17 @@ main (int argc, char **argv) s.add (12); hb_vector_t v (hb_iter (s)); + hb_vector_t V (hb_iter (s)); assert (v.length == 2); + assert (V.length == 2); assert (v[0] == 12); + assert (V[0] == 12); assert (v[1] == 18); + assert (V[1] == 18); } - /* Test initializing vector from initializer list and swapping. */ + /* Test initializing from initializer list and swapping. */ { hb_vector_t v1 {1, 2, 3}; hb_vector_t v2 {4, 5}; From d2c364f6e7edbd295132f792d711ac37ff551d37 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 21:55:14 -0600 Subject: [PATCH 15/32] [array] Use default methods --- src/hb-array.hh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hb-array.hh b/src/hb-array.hh index ab0dd6ebe..8cae3c995 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -50,10 +50,11 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> /* * Constructors. */ - hb_array_t () : arrayZ (nullptr), length (0), backwards_length (0) {} - hb_array_t (Type *array_, unsigned int length_) : arrayZ (array_), length (length_), backwards_length (0) {} + hb_array_t () = default; + ~hb_array_t () = default; + hb_array_t (Type *array_, unsigned int length_) : arrayZ (array_), length (length_) {} template - hb_array_t (Type (&array_)[length_]) : arrayZ (array_), length (length_), backwards_length (0) {} + hb_array_t (Type (&array_)[length_]) : hb_array_t (array_, length_) {} template @@ -281,9 +282,9 @@ struct hb_array_t : hb_iter_with_fallback_t, Type&> */ public: - Type *arrayZ; - unsigned int length; - unsigned int backwards_length; + Type *arrayZ = nullptr; + unsigned int length = 0; + unsigned int backwards_length = 0; }; template inline hb_array_t hb_array (T *array, unsigned int length) @@ -302,7 +303,7 @@ struct hb_sorted_array_t : static constexpr bool is_random_access_iterator = true; static constexpr bool is_sorted_iterator = true; - hb_sorted_array_t () : hb_array_t () {} + hb_sorted_array_t () = default; hb_sorted_array_t (Type *array_, unsigned int length_) : hb_array_t (array_, length_) {} template hb_sorted_array_t (Type (&array_)[length_]) : hb_array_t (array_) {} From b860b44229dbde49e8a1ed34257b1a70bb2401ee Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 22:00:18 -0600 Subject: [PATCH 16/32] [bimap] Simplify initialization --- src/hb-bimap.hh | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/hb-bimap.hh b/src/hb-bimap.hh index d40988075..d466af8b6 100644 --- a/src/hb-bimap.hh +++ b/src/hb-bimap.hh @@ -33,15 +33,14 @@ /* Bi-directional map */ struct hb_bimap_t { - hb_bimap_t () { init (); } - ~hb_bimap_t () { fini (); } - + /* XXX(remove) */ void init () { forw_map.init (); back_map.init (); } + /* XXX(remove) */ void fini () { forw_map.fini (); @@ -99,14 +98,6 @@ struct hb_bimap_t /* Inremental bimap: only lhs is given, rhs is incrementally assigned */ struct hb_inc_bimap_t : hb_bimap_t { - hb_inc_bimap_t () { init (); } - - void init () - { - hb_bimap_t::init (); - next_value = 0; - } - /* Add a mapping from lhs to rhs with a unique value if lhs is unknown. * Return the rhs value as the result. */ @@ -165,7 +156,7 @@ struct hb_inc_bimap_t : hb_bimap_t } protected: - unsigned int next_value; + unsigned int next_value = 0; }; #endif /* HB_BIMAP_HH */ From 38debbab7e287e513968c80a10e69ab054acad4d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 22:17:35 -0600 Subject: [PATCH 17/32] [set] Add successful check in swap() --- src/hb-bit-set-invertible.hh | 2 ++ src/hb-bit-set.hh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/hb-bit-set-invertible.hh b/src/hb-bit-set-invertible.hh index 978d589ab..0832b0fc2 100644 --- a/src/hb-bit-set-invertible.hh +++ b/src/hb-bit-set-invertible.hh @@ -44,6 +44,8 @@ struct hb_bit_set_invertible_t hb_bit_set_invertible_t& operator= (hb_bit_set_invertible_t&& o) = default; friend void swap (hb_bit_set_invertible_t &a, hb_bit_set_invertible_t &b) { + if (likely (!a.s.successful || !b.s.successful)) + return; hb_swap (a.inverted, b.inverted); hb_swap (a.s, b.s); } diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index 9f76e81ce..fd793696b 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -44,6 +44,8 @@ struct hb_bit_set_t hb_bit_set_t& operator= (hb_bit_set_t&& other) { hb_swap (*this, other); return *this; } friend void swap (hb_bit_set_t &a, hb_bit_set_t &b) { + if (likely (!a.successful || !b.successful)) + return; hb_swap (a.successful, b.successful); hb_swap (a.population, b.population); hb_swap (a.last_page_lookup, b.last_page_lookup); From c30f6834d0ad0adbe0f16bb79555fd161de2303e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 22:29:14 -0600 Subject: [PATCH 18/32] [map] Add 5 methods --- src/Makefile.am | 5 ++++ src/hb-map.hh | 17 +++++++++++- src/meson.build | 1 + src/test-map.cc | 68 ++++++++++++++++++++++++++++++++++++++++++++++ src/test-set.cc | 1 + src/test-vector.cc | 1 + 6 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/test-map.cc diff --git a/src/Makefile.am b/src/Makefile.am index bd88fa05a..1bccc5e96 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -346,6 +346,7 @@ COMPILED_TESTS = \ test-algs \ test-array \ test-iter \ + test-map \ test-meta \ test-number \ test-ot-tag \ @@ -381,6 +382,10 @@ test_iter_SOURCES = test-iter.cc hb-static.cc test_iter_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) test_iter_LDADD = $(COMPILED_TESTS_LDADD) +test_map_SOURCES = test-map.cc hb-static.cc +test_map_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) +test_map_LDADD = $(COMPILED_TESTS_LDADD) + test_meta_SOURCES = test-meta.cc hb-static.cc test_meta_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) test_meta_LDADD = $(COMPILED_TESTS_LDADD) diff --git a/src/hb-map.hh b/src/hb-map.hh index dcd5267d7..d7b20f3e2 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -39,10 +39,14 @@ template struct hb_hashmap_t { - HB_DELETE_COPY_ASSIGN (hb_hashmap_t); hb_hashmap_t () { init (); } ~hb_hashmap_t () { fini (); } + hb_hashmap_t (const hb_hashmap_t& o) : hb_hashmap_t () { hb_copy (o, *this); } + hb_hashmap_t (hb_hashmap_t&& o) : hb_hashmap_t () { hb_swap (*this, o); } + hb_hashmap_t& operator= (const hb_hashmap_t&& o) { hb_copy (o, *this); return *this; } + hb_hashmap_t& operator= (hb_hashmap_t&& o) { hb_swap (*this, o); return *this; } + static_assert (hb_is_integral (K) || hb_is_pointer (K), ""); static_assert (hb_is_integral (V) || hb_is_pointer (V), ""); @@ -70,6 +74,17 @@ struct hb_hashmap_t unsigned int prime; item_t *items; + friend void swap (hb_hashmap_t& a, hb_hashmap_t& b) + { + if (unlikely (!a.successful || !b.successful)) + return; + hb_swap (a.successful, b.successful); + hb_swap (a.population, b.population); + hb_swap (a.occupancy, b.occupancy); + hb_swap (a.mask, b.mask); + hb_swap (a.prime, b.prime); + hb_swap (a.items, b.items); + } void init_shallow () { successful = true; diff --git a/src/meson.build b/src/meson.build index ca40176ab..61b3dce0e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -488,6 +488,7 @@ if get_option('tests').enabled() 'test-repacker': ['test-repacker.cc', 'hb-static.cc'], 'test-priority-queue': ['test-priority-queue.cc', 'hb-static.cc'], 'test-iter': ['test-iter.cc', 'hb-static.cc'], + 'test-map': ['test-map.cc', 'hb-static.cc'], 'test-meta': ['test-meta.cc', 'hb-static.cc'], 'test-number': ['test-number.cc', 'hb-number.cc'], 'test-ot-tag': ['hb-ot-tag.cc'], diff --git a/src/test-map.cc b/src/test-map.cc new file mode 100644 index 000000000..b685530bd --- /dev/null +++ b/src/test-map.cc @@ -0,0 +1,68 @@ +/* + * Copyright © 2021 Behdad Esfahbod + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + */ + +#include "hb.hh" +#include "hb-map.hh" + + +int +main (int argc, char **argv) +{ + + /* Test copy constructor. */ + { + hb_map_t v1; + v1.set (1, 2); + hb_map_t v2 {v1}; + assert (v1.get_population () == 1); + assert (v2.get_population () == 1); + assert (v1[1] == 2); + assert (v2[1] == 2); + } + + /* Test copy assignment. */ + { + hb_map_t v1; + v1.set (1, 2); + hb_map_t v2 = v1; + assert (v1.get_population () == 1); + assert (v2.get_population () == 1); + assert (v1[1] == 2); + assert (v2[1] == 2); + } + + /* Test move constructor. */ + { + hb_map_t v {hb_map_t {}}; + } + + /* Test move assignment. */ + { + hb_map_t v; + v = hb_map_t {}; + } + + return 0; +} diff --git a/src/test-set.cc b/src/test-set.cc index 531df175a..5c28beb34 100644 --- a/src/test-set.cc +++ b/src/test-set.cc @@ -59,6 +59,7 @@ main (int argc, char **argv) v = hb_set_t {1, 2}; assert (v.get_population () == 2); } + /* Test initializing set from iterable. */ { hb_set_t s; diff --git a/src/test-vector.cc b/src/test-vector.cc index 7dacec818..6418a84ae 100644 --- a/src/test-vector.cc +++ b/src/test-vector.cc @@ -77,6 +77,7 @@ main (int argc, char **argv) assert (v[0] == 1); assert (v[1] == 2); } + /* Test initializing from iterable. */ { hb_set_t s; From 3604f5f2484b47c0693896f8a8e48dfe46dddef1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 22:37:42 -0600 Subject: [PATCH 19/32] [algs] Include --- src/hb-algs.hh | 1 + src/hb-set.hh | 2 -- src/hb-vector.hh | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index fc1aeb0bf..3ebbc3345 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -35,6 +35,7 @@ #include "hb-number.hh" #include +#include /* * Flags diff --git a/src/hb-set.hh b/src/hb-set.hh index 58188b516..dadcb514e 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -31,8 +31,6 @@ #include "hb.hh" #include "hb-bit-set-invertible.hh" -#include - template struct hb_sparseset_t diff --git a/src/hb-vector.hh b/src/hb-vector.hh index c34498bbc..b9239218f 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -31,8 +31,6 @@ #include "hb-array.hh" #include "hb-null.hh" -#include - template struct hb_vector_t From a03b9b14c988aa04ba3ee1e5d187b65e7b24015a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 22:45:11 -0600 Subject: [PATCH 20/32] [map] Add initializer_list and swap() --- src/hb-map.hh | 23 ++++++++++++++++++++++- src/test-map.cc | 10 ++++++++++ src/test-set.cc | 6 +++--- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index d7b20f3e2..45bd3cb36 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -47,6 +47,12 @@ struct hb_hashmap_t hb_hashmap_t& operator= (const hb_hashmap_t&& o) { hb_copy (o, *this); return *this; } hb_hashmap_t& operator= (hb_hashmap_t&& o) { hb_swap (*this, o); return *this; } + hb_hashmap_t (std::initializer_list> lst) : hb_hashmap_t () + { + for (auto&& item : lst) + set (item.first, item.second); + } + static_assert (hb_is_integral (K) || hb_is_pointer (K), ""); static_assert (hb_is_integral (V) || hb_is_pointer (V), ""); @@ -336,7 +342,22 @@ struct hb_hashmap_t struct hb_map_t : hb_hashmap_t {}; + HB_MAP_VALUE_INVALID> +{ + using hashmap = hb_hashmap_t; + hb_map_t () = default; + ~hb_map_t () = default; + hb_map_t (hb_map_t& o) = default; + hb_map_t& operator= (const hb_map_t& other) = default; + hb_map_t& operator= (hb_map_t&& other) = default; + hb_map_t (std::initializer_list> lst) : hashmap (lst) {} + template + hb_map_t (const Iterable &o) : hashmap (o) {} +}; #endif /* HB_MAP_HH */ diff --git a/src/test-map.cc b/src/test-map.cc index b685530bd..2d0305809 100644 --- a/src/test-map.cc +++ b/src/test-map.cc @@ -64,5 +64,15 @@ main (int argc, char **argv) v = hb_map_t {}; } + /* Test initializing from initializer list and swapping. */ + { + using pair_t = hb_pair_t; + hb_map_t v1 {pair_t{1,2}, pair_t{4,5}}; + hb_map_t v2 {pair_t{3,4}}; + hb_swap (v1, v2); + assert (v1.get_population () == 1); + assert (v2.get_population () == 2); + } + return 0; } diff --git a/src/test-set.cc b/src/test-set.cc index 5c28beb34..286f1a997 100644 --- a/src/test-set.cc +++ b/src/test-set.cc @@ -60,7 +60,7 @@ main (int argc, char **argv) assert (v.get_population () == 2); } - /* Test initializing set from iterable. */ + /* Test initializing from iterable. */ { hb_set_t s; @@ -72,7 +72,7 @@ main (int argc, char **argv) assert (v.get_population () == 2); } - /* Test initializing set from iterator. */ + /* Test initializing from iterator. */ { hb_set_t s; @@ -84,7 +84,7 @@ main (int argc, char **argv) assert (v.get_population () == 2); } - /* Test initializing set from initializer list and swapping. */ + /* Test initializing from initializer list and swapping. */ { hb_set_t v1 {1, 2, 3}; hb_set_t v2 {4, 5}; From 94158316d9ba69315497a200ec63d13cb6959363 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 22:47:26 -0600 Subject: [PATCH 21/32] [map] Add iterable constructor --- src/hb-map.hh | 6 ++++++ src/test-map.cc | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/hb-map.hh b/src/hb-map.hh index 45bd3cb36..e4b7910a7 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -52,6 +52,12 @@ struct hb_hashmap_t for (auto&& item : lst) set (item.first, item.second); } + template + hb_hashmap_t (const Iterable &o) : hb_hashmap_t () + { + hb_copy (o, *this); + } static_assert (hb_is_integral (K) || hb_is_pointer (K), ""); static_assert (hb_is_integral (V) || hb_is_pointer (V), ""); diff --git a/src/test-map.cc b/src/test-map.cc index 2d0305809..5761cc8d6 100644 --- a/src/test-map.cc +++ b/src/test-map.cc @@ -64,6 +64,30 @@ main (int argc, char **argv) v = hb_map_t {}; } + /* Test initializing from iterable. */ + { + hb_map_t s; + + s.set (1, 2); + s.set (3, 4); + + hb_map_t v (s); + + assert (v.get_population () == 2); + } + + /* Test initializing from iterator. */ + { + hb_map_t s; + + s.set (1, 2); + s.set (3, 4); + + hb_map_t v (hb_iter (s)); + + assert (v.get_population () == 2); + } + /* Test initializing from initializer list and swapping. */ { using pair_t = hb_pair_t; From a28ea8d7f35a89cda49a9552a5ab6dc14d208c84 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 22:50:54 -0600 Subject: [PATCH 22/32] Simplify swap() --- src/hb-bit-set.hh | 1 - src/hb-map.hh | 1 - 2 files changed, 2 deletions(-) diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index fd793696b..a471ee48b 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -46,7 +46,6 @@ struct hb_bit_set_t { if (likely (!a.successful || !b.successful)) return; - hb_swap (a.successful, b.successful); hb_swap (a.population, b.population); hb_swap (a.last_page_lookup, b.last_page_lookup); hb_swap (a.page_map, b.page_map); diff --git a/src/hb-map.hh b/src/hb-map.hh index e4b7910a7..196b8e76a 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -90,7 +90,6 @@ struct hb_hashmap_t { if (unlikely (!a.successful || !b.successful)) return; - hb_swap (a.successful, b.successful); hb_swap (a.population, b.population); hb_swap (a.occupancy, b.occupancy); hb_swap (a.mask, b.mask); From 4c6fd7cdb2f2ab60de83d9a1e0fd189510b771a0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 23:13:34 -0600 Subject: [PATCH 23/32] [map] Try moving items when resizing --- src/hb-map.hh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index 196b8e76a..696cb8713 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -159,17 +159,15 @@ struct hb_hashmap_t if (old_items[i].is_real ()) set_with_hash (old_items[i].key, old_items[i].hash, - old_items[i].value); + hb_move (old_items[i].value)); hb_free (old_items); return true; } - bool set (K key, V value) - { - return set_with_hash (key, hb_hash (key), value); - } + bool set (K key, const V& value) { return set_with_hash (key, hb_hash (key), value); } + bool set (K key, V&& value) { return set_with_hash (key, hb_hash (key), hb_move (value)); } V get (K key) const { @@ -239,7 +237,8 @@ struct hb_hashmap_t protected: - bool set_with_hash (K key, uint32_t hash, V value) + template + bool set_with_hash (K key, uint32_t hash, VV&& value) { if (unlikely (!successful)) return false; if (unlikely (key == kINVALID)) return true; From 30c05e8b55c36200735446f237f1d7003cb70450 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 1 Nov 2021 23:57:00 -0600 Subject: [PATCH 24/32] [algs] include --- src/hb-algs.hh | 1 + src/hb-mutex.hh | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 3ebbc3345..7b3a003e8 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -36,6 +36,7 @@ #include #include +#include /* * Flags diff --git a/src/hb-mutex.hh b/src/hb-mutex.hh index 29c3f8b82..4e135027f 100644 --- a/src/hb-mutex.hh +++ b/src/hb-mutex.hh @@ -73,7 +73,6 @@ typedef CRITICAL_SECTION hb_mutex_impl_t; #elif !defined(HB_NO_MT) #include -#include typedef std::mutex hb_mutex_impl_t; #define hb_mutex_impl_init(M) HB_STMT_START { new (M) hb_mutex_impl_t; } HB_STMT_END #define hb_mutex_impl_lock(M) (M)->lock () From be42800fc6d90340f843fa03be1bb06b0453e519 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 2 Nov 2021 00:04:18 -0600 Subject: [PATCH 25/32] [meta] Use std::is_trivially_... instead of internal copies --- src/hb-meta.hh | 58 ++------------------------------------------- src/hb-open-type.hh | 10 ++++---- src/test-meta.cc | 16 ------------- 3 files changed, 7 insertions(+), 77 deletions(-) diff --git a/src/hb-meta.hh b/src/hb-meta.hh index a714bc2bf..a5cbe48da 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -29,6 +29,8 @@ #include "hb.hh" +#include + /* * C++ template meta-programming & fundamentals used with them. @@ -355,62 +357,6 @@ using hb_is_move_assignable = hb_is_assignable, hb_add_rvalue_reference>; #define hb_is_move_assignable(T) hb_is_move_assignable::value -/* Trivial versions. */ - -template union hb_trivial { T value; }; - -template -using hb_is_trivially_destructible= hb_is_destructible>; -#define hb_is_trivially_destructible(T) hb_is_trivially_destructible::value - -/* Don't know how to do the following. */ -//template -//using hb_is_trivially_constructible= hb_is_constructible, hb_trivial...>; -//#define hb_is_trivially_constructible(...) hb_is_trivially_constructible<__VA_ARGS__>::value - -template -using hb_is_trivially_default_constructible= hb_is_default_constructible>; -#define hb_is_trivially_default_constructible(T) hb_is_trivially_default_constructible::value - -template -using hb_is_trivially_copy_constructible= hb_is_copy_constructible>; -#define hb_is_trivially_copy_constructible(T) hb_is_trivially_copy_constructible::value - -template -using hb_is_trivially_move_constructible= hb_is_move_constructible>; -#define hb_is_trivially_move_constructible(T) hb_is_trivially_move_constructible::value - -/* Don't know how to do the following. */ -//template -//using hb_is_trivially_assignable= hb_is_assignable, hb_trivial>; -//#define hb_is_trivially_assignable(T,U) hb_is_trivially_assignable::value - -template -using hb_is_trivially_copy_assignable= hb_is_copy_assignable>; -#define hb_is_trivially_copy_assignable(T) hb_is_trivially_copy_assignable::value - -template -using hb_is_trivially_move_assignable= hb_is_move_assignable>; -#define hb_is_trivially_move_assignable(T) hb_is_trivially_move_assignable::value - -template -using hb_is_trivially_copyable= hb_bool_constant< - hb_is_trivially_destructible (T) && - (!hb_is_move_assignable (T) || hb_is_trivially_move_assignable (T)) && - (!hb_is_move_constructible (T) || hb_is_trivially_move_constructible (T)) && - (!hb_is_copy_assignable (T) || hb_is_trivially_copy_assignable (T)) && - (!hb_is_copy_constructible (T) || hb_is_trivially_copy_constructible (T)) && - true ->; -#define hb_is_trivially_copyable(T) hb_is_trivially_copyable::value - -template -using hb_is_trivial= hb_bool_constant< - hb_is_trivially_copyable (T) && - hb_is_trivially_default_constructible (T) ->; -#define hb_is_trivial(T) hb_is_trivial::value - /* hb_unwrap_type (T) * If T has no T::type, returns T. Otherwise calls itself on T::type recursively. */ diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 5199d1c48..129aa868d 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -518,7 +518,7 @@ struct UnsizedArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c, count))) return_trace (false); - if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); + if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); for (unsigned int i = 0; i < count; i++) if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) return_trace (false); @@ -707,7 +707,7 @@ struct ArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); + if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = len; for (unsigned int i = 0; i < count; i++) if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) @@ -835,7 +835,7 @@ struct HeadlessArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); + if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = get_length (); for (unsigned int i = 0; i < count; i++) if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) @@ -884,7 +884,7 @@ struct ArrayOfM1 { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); + if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = lenM1 + 1; for (unsigned int i = 0; i < count; i++) if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) @@ -1070,7 +1070,7 @@ struct VarSizedBinSearchArrayOf { TRACE_SANITIZE (this); if (unlikely (!sanitize_shallow (c))) return_trace (false); - if (!sizeof... (Ts) && hb_is_trivially_copyable (Type)) return_trace (true); + if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = get_length (); for (unsigned int i = 0; i < count; i++) if (unlikely (!(*this)[i].sanitize (c, hb_forward (ds)...))) diff --git a/src/test-meta.cc b/src/test-meta.cc index 9436b9038..a26321565 100644 --- a/src/test-meta.cc +++ b/src/test-meta.cc @@ -108,22 +108,6 @@ main (int argc, char **argv) static_assert (hb_is_constructible (X, Y), ""); static_assert (!hb_is_constructible (Y, X), ""); - static_assert (hb_is_trivially_default_constructible (X), ""); - static_assert (hb_is_trivially_default_constructible (Y), ""); - static_assert (hb_is_trivially_copy_constructible (X), ""); - static_assert (hb_is_trivially_copy_constructible (Y), ""); - static_assert (hb_is_trivially_move_constructible (X), ""); - static_assert (hb_is_trivially_move_constructible (Y), ""); - static_assert (hb_is_trivially_destructible (Y), ""); - - static_assert (hb_is_trivially_copyable (int), ""); - static_assert (hb_is_trivially_copyable (X), ""); - static_assert (hb_is_trivially_copyable (Y), ""); - - static_assert (hb_is_trivial (int), ""); - static_assert (hb_is_trivial (X), ""); - static_assert (hb_is_trivial (Y), ""); - static_assert (hb_is_signed (hb_unwrap_type (U>>)), ""); static_assert (hb_is_unsigned (hb_unwrap_type (U>>>)), ""); From 896e0c74a82eb65f80d284a5d4f6557960de2620 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 2 Nov 2021 00:06:30 -0600 Subject: [PATCH 26/32] [meta] Remove unused traits --- src/hb-meta.hh | 46 ---------------------------------------------- src/test-meta.cc | 13 ------------- 2 files changed, 59 deletions(-) diff --git a/src/hb-meta.hh b/src/hb-meta.hh index a5cbe48da..802509b81 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -311,52 +311,6 @@ template <> struct hb_int_max : hb_integral_constant -struct _hb_is_destructible : hb_false_type {}; -template -struct _hb_is_destructible> : hb_true_type {}; -template -using hb_is_destructible = _hb_is_destructible; -#define hb_is_destructible(T) hb_is_destructible::value - -template -struct _hb_is_constructible : hb_false_type {}; -template -struct _hb_is_constructible, Ts...> : hb_true_type {}; -template -using hb_is_constructible = _hb_is_constructible; -#define hb_is_constructible(...) hb_is_constructible<__VA_ARGS__>::value - -template -using hb_is_default_constructible = hb_is_constructible; -#define hb_is_default_constructible(T) hb_is_default_constructible::value - -template -using hb_is_copy_constructible = hb_is_constructible>>; -#define hb_is_copy_constructible(T) hb_is_copy_constructible::value - -template -using hb_is_move_constructible = hb_is_constructible>>; -#define hb_is_move_constructible(T) hb_is_move_constructible::value - -template -struct _hb_is_assignable : hb_false_type {}; -template -struct _hb_is_assignable> : hb_true_type {}; -template -using hb_is_assignable = _hb_is_assignable; -#define hb_is_assignable(T,U) hb_is_assignable::value - -template -using hb_is_copy_assignable = hb_is_assignable, - hb_add_lvalue_reference>>; -#define hb_is_copy_assignable(T) hb_is_copy_assignable::value - -template -using hb_is_move_assignable = hb_is_assignable, - hb_add_rvalue_reference>; -#define hb_is_move_assignable(T) hb_is_move_assignable::value - /* hb_unwrap_type (T) * If T has no T::type, returns T. Otherwise calls itself on T::type recursively. */ diff --git a/src/test-meta.cc b/src/test-meta.cc index a26321565..c6715ac58 100644 --- a/src/test-meta.cc +++ b/src/test-meta.cc @@ -95,19 +95,6 @@ main (int argc, char **argv) static_assert (hb_is_base_of (X, const Y), ""); static_assert (!hb_is_base_of (Y, X), ""); - static_assert (hb_is_constructible (int), ""); - static_assert (hb_is_constructible (int, int), ""); - static_assert (hb_is_constructible (int, char), ""); - static_assert (hb_is_constructible (int, long), ""); - static_assert (!hb_is_constructible (int, X), ""); - static_assert (!hb_is_constructible (int, int, int), ""); - static_assert (hb_is_constructible (X), ""); - static_assert (!hb_is_constructible (X, int), ""); - static_assert (hb_is_constructible (X, X), ""); - static_assert (!hb_is_constructible (X, X, X), ""); - static_assert (hb_is_constructible (X, Y), ""); - static_assert (!hb_is_constructible (Y, X), ""); - static_assert (hb_is_signed (hb_unwrap_type (U>>)), ""); static_assert (hb_is_unsigned (hb_unwrap_type (U>>>)), ""); From 811f80a701a7e40d8ef2e01b927da74015aa6113 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 2 Nov 2021 00:14:34 -0600 Subject: [PATCH 27/32] [algs] Use std::move instead of hb_move() --- src/hb-map.hh | 4 ++-- src/hb-meta.hh | 6 ++---- src/hb-set.hh | 2 +- src/hb-vector.hh | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index 696cb8713..c14a52af0 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -159,7 +159,7 @@ struct hb_hashmap_t if (old_items[i].is_real ()) set_with_hash (old_items[i].key, old_items[i].hash, - hb_move (old_items[i].value)); + std::move (old_items[i].value)); hb_free (old_items); @@ -167,7 +167,7 @@ struct hb_hashmap_t } bool set (K key, const V& value) { return set_with_hash (key, hb_hash (key), value); } - bool set (K key, V&& value) { return set_with_hash (key, hb_hash (key), hb_move (value)); } + bool set (K key, V&& value) { return set_with_hash (key, hb_hash (key), std::move (value)); } V get (K key) const { diff --git a/src/hb-meta.hh b/src/hb-meta.hh index 802509b81..a2c32003b 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -30,6 +30,7 @@ #include "hb.hh" #include +#include /* @@ -174,10 +175,7 @@ using hb_is_cr_convertible = hb_bool_constant< >; #define hb_is_cr_convertible(From,To) hb_is_cr_convertible::value -/* std::move and std::forward */ - -template -static constexpr hb_remove_reference&& hb_move (T&& t) { return (hb_remove_reference&&) (t); } +/* std::forward */ template static constexpr T&& hb_forward (hb_remove_reference& t) { return (T&&) t; } diff --git a/src/hb-set.hh b/src/hb-set.hh index dadcb514e..884142718 100644 --- a/src/hb-set.hh +++ b/src/hb-set.hh @@ -42,7 +42,7 @@ struct hb_sparseset_t ~hb_sparseset_t () { fini (); } hb_sparseset_t (const hb_sparseset_t& other) : hb_sparseset_t () { set (other); } - hb_sparseset_t (hb_sparseset_t&& other) : hb_sparseset_t () { s = hb_move (other.s); } + hb_sparseset_t (hb_sparseset_t&& other) : hb_sparseset_t () { s = std::move (other.s); } hb_sparseset_t& operator= (const hb_sparseset_t& other) { set (other); return *this; } hb_sparseset_t& operator= (hb_sparseset_t&& other) { hb_swap (*this, other); return *this; } friend void swap (hb_sparseset_t& a, hb_sparseset_t& b) { hb_swap (a.s, b.s); } diff --git a/src/hb-vector.hh b/src/hb-vector.hh index b9239218f..df6b08628 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -255,7 +255,7 @@ struct hb_vector_t Type pop () { if (!length) return Null (Type); - return hb_move (arrayZ[--length]); /* Does this move actually work? */ + return std::move (arrayZ[--length]); /* Does this move actually work? */ } void remove (unsigned int i) From 6d555ce82e50bdd54896a89d9d547493b466b116 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 2 Nov 2021 00:18:22 -0600 Subject: [PATCH 28/32] [meta] Use std::forward instead of hb_forward() --- src/hb-aat-layout-common.hh | 2 +- src/hb-aat-layout-kerx-table.hh | 10 ++--- src/hb-aat-layout-morx-table.hh | 10 ++--- src/hb-algs.hh | 80 ++++++++++++++++----------------- src/hb-debug.hh | 8 ++-- src/hb-dispatch.hh | 2 +- src/hb-iter.hh | 14 +++--- src/hb-meta.hh | 10 +---- src/hb-open-type.hh | 22 ++++----- src/hb-ot-cff-common.hh | 2 +- src/hb-ot-color-colr-table.hh | 68 ++++++++++++++-------------- src/hb-ot-kern-table.hh | 8 ++-- src/hb-ot-layout-common.hh | 4 +- src/hb-ot-layout-gdef-table.hh | 6 +-- src/hb-ot-layout-gpos-table.hh | 36 +++++++-------- src/hb-ot-layout-gsub-table.hh | 30 ++++++------- src/hb-ot-layout-gsubgpos.hh | 16 +++---- src/hb-ot-layout.cc | 4 +- src/hb-sanitize.hh | 6 +-- src/hb-serialize.hh | 16 +++---- src/hb-subset.hh | 6 +-- src/hb-vector.hh | 4 +- 22 files changed, 179 insertions(+), 185 deletions(-) diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index f20416c17..1dcbe9290 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -162,7 +162,7 @@ struct LookupSegmentArray TRACE_SANITIZE (this); return_trace (c->check_struct (this) && first <= last && - valuesZ.sanitize (c, base, last - first + 1, hb_forward (ds)...)); + valuesZ.sanitize (c, base, last - first + 1, std::forward (ds)...)); } HBGlyphID16 last; /* Last GlyphID in this segment */ diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index e4278f199..0354b47d5 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -775,11 +775,11 @@ struct KerxSubTable unsigned int subtable_type = get_type (); TRACE_DISPATCH (this, subtable_type); switch (subtable_type) { - case 0: return_trace (c->dispatch (u.format0, hb_forward (ds)...)); - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); - case 4: return_trace (c->dispatch (u.format4, hb_forward (ds)...)); - case 6: return_trace (c->dispatch (u.format6, hb_forward (ds)...)); + case 0: return_trace (c->dispatch (u.format0, std::forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 4: return_trace (c->dispatch (u.format4, std::forward (ds)...)); + case 6: return_trace (c->dispatch (u.format6, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 377ef8721..b77c1f4d4 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -906,11 +906,11 @@ struct ChainSubtable unsigned int subtable_type = get_type (); TRACE_DISPATCH (this, subtable_type); switch (subtable_type) { - case Rearrangement: return_trace (c->dispatch (u.rearrangement, hb_forward (ds)...)); - case Contextual: return_trace (c->dispatch (u.contextual, hb_forward (ds)...)); - case Ligature: return_trace (c->dispatch (u.ligature, hb_forward (ds)...)); - case Noncontextual: return_trace (c->dispatch (u.noncontextual, hb_forward (ds)...)); - case Insertion: return_trace (c->dispatch (u.insertion, hb_forward (ds)...)); + case Rearrangement: return_trace (c->dispatch (u.rearrangement, std::forward (ds)...)); + case Contextual: return_trace (c->dispatch (u.contextual, std::forward (ds)...)); + case Ligature: return_trace (c->dispatch (u.ligature, std::forward (ds)...)); + case Noncontextual: return_trace (c->dispatch (u.noncontextual, std::forward (ds)...)); + case Insertion: return_trace (c->dispatch (u.insertion, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 7b3a003e8..55c92841f 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -182,7 +182,7 @@ struct { /* Note. This is dangerous in that if it's passed an rvalue, it returns rvalue-reference. */ template constexpr auto - operator () (T&& v) const HB_AUTO_RETURN ( hb_forward (v) ) + operator () (T&& v) const HB_AUTO_RETURN ( std::forward (v) ) } HB_FUNCOBJ (hb_identity); struct @@ -206,7 +206,7 @@ HB_FUNCOBJ (hb_ridentity); struct { template constexpr bool - operator () (T&& v) const { return bool (hb_forward (v)); } + operator () (T&& v) const { return bool (std::forward (v)); } } HB_FUNCOBJ (hb_bool); @@ -240,26 +240,26 @@ struct /* Pointer-to-member-function. */ template auto impl (Appl&& a, hb_priority<2>, T &&v, Ts&&... ds) const HB_AUTO_RETURN - ((hb_deref (hb_forward (v)).*hb_forward (a)) (hb_forward (ds)...)) + ((hb_deref (std::forward (v)).*std::forward (a)) (std::forward (ds)...)) /* Pointer-to-member. */ template auto impl (Appl&& a, hb_priority<1>, T &&v) const HB_AUTO_RETURN - ((hb_deref (hb_forward (v))).*hb_forward (a)) + ((hb_deref (std::forward (v))).*std::forward (a)) /* Operator(). */ template auto impl (Appl&& a, hb_priority<0>, Ts&&... ds) const HB_AUTO_RETURN - (hb_deref (hb_forward (a)) (hb_forward (ds)...)) + (hb_deref (std::forward (a)) (std::forward (ds)...)) public: template auto operator () (Appl&& a, Ts&&... ds) const HB_AUTO_RETURN ( - impl (hb_forward (a), + impl (std::forward (a), hb_prioritize, - hb_forward (ds)...) + std::forward (ds)...) ) } HB_FUNCOBJ (hb_invoke); @@ -278,9 +278,9 @@ struct hb_partial_t hb_declval (V), hb_declval (Ts)...)) { - return hb_invoke (hb_forward (a), - hb_forward (v), - hb_forward (ds)...); + return hb_invoke (std::forward (a), + std::forward (v), + std::forward (ds)...); } template (a), - hb_forward (d0), - hb_forward (v), - hb_forward (ds)...); + return hb_invoke (std::forward (a), + std::forward (d0), + std::forward (v), + std::forward (ds)...); } private: @@ -327,14 +327,14 @@ auto hb_partial (Appl&& a, V&& v) HB_AUTO_RETURN #define HB_PARTIALIZE(Pos) \ template \ decltype(auto) operator () (_T&& _v) const \ - { return hb_partial (this, hb_forward<_T> (_v)); } \ + { return hb_partial (this, std::forward<_T> (_v)); } \ static_assert (true, "") #else /* https://github.com/harfbuzz/harfbuzz/issues/1724 */ #define HB_PARTIALIZE(Pos) \ template \ auto operator () (_T&& _v) const HB_AUTO_RETURN \ - (hb_partial (+this, hb_forward<_T> (_v))) \ + (hb_partial (+this, std::forward<_T> (_v))) \ static_assert (true, "") #endif @@ -346,22 +346,22 @@ struct template auto impl (Pred&& p, Val &&v, hb_priority<1>) const HB_AUTO_RETURN ( - hb_deref (hb_forward (p)).has (hb_forward (v)) + hb_deref (std::forward (p)).has (std::forward (v)) ) template auto impl (Pred&& p, Val &&v, hb_priority<0>) const HB_AUTO_RETURN ( - hb_invoke (hb_forward (p), - hb_forward (v)) + hb_invoke (std::forward (p), + std::forward (v)) ) public: template auto operator () (Pred&& p, Val &&v) const HB_RETURN (bool, - impl (hb_forward (p), - hb_forward (v), + impl (std::forward (p), + std::forward (v), hb_prioritize) ) } @@ -374,22 +374,22 @@ struct template auto impl (Pred&& p, Val &&v, hb_priority<1>) const HB_AUTO_RETURN ( - hb_has (hb_forward (p), - hb_forward (v)) + hb_has (std::forward (p), + std::forward (v)) ) template auto impl (Pred&& p, Val &&v, hb_priority<0>) const HB_AUTO_RETURN ( - hb_forward (p) == hb_forward (v) + std::forward (p) == std::forward (v) ) public: template auto operator () (Pred&& p, Val &&v) const HB_RETURN (bool, - impl (hb_forward (p), - hb_forward (v), + impl (std::forward (p), + std::forward (v), hb_prioritize) ) } @@ -402,20 +402,20 @@ struct template auto impl (Proj&& f, Val &&v, hb_priority<2>) const HB_AUTO_RETURN ( - hb_deref (hb_forward (f)).get (hb_forward (v)) + hb_deref (std::forward (f)).get (std::forward (v)) ) template auto impl (Proj&& f, Val &&v, hb_priority<1>) const HB_AUTO_RETURN ( - hb_invoke (hb_forward (f), - hb_forward (v)) + hb_invoke (std::forward (f), + std::forward (v)) ) template auto impl (Proj&& f, Val &&v, hb_priority<0>) const HB_AUTO_RETURN ( - hb_forward (f)[hb_forward (v)] + std::forward (f)[std::forward (v)] ) public: @@ -423,8 +423,8 @@ struct template auto operator () (Proj&& f, Val &&v) const HB_AUTO_RETURN ( - impl (hb_forward (f), - hb_forward (v), + impl (std::forward (f), + std::forward (v), hb_prioritize) ) } @@ -437,19 +437,19 @@ struct template auto impl (T1&& v1, T2 &&v2, hb_priority<2>) const HB_AUTO_RETURN ( - hb_forward (v2).cmp (hb_forward (v1)) == 0 + std::forward (v2).cmp (std::forward (v1)) == 0 ) template auto impl (T1&& v1, T2 &&v2, hb_priority<1>) const HB_AUTO_RETURN ( - hb_forward (v1).cmp (hb_forward (v2)) == 0 + std::forward (v1).cmp (std::forward (v2)) == 0 ) template auto impl (T1&& v1, T2 &&v2, hb_priority<0>) const HB_AUTO_RETURN ( - hb_forward (v1) == hb_forward (v2) + std::forward (v1) == std::forward (v2) ) public: @@ -457,8 +457,8 @@ struct template auto operator () (T1&& v1, T2 &&v2) const HB_AUTO_RETURN ( - impl (hb_forward (v1), - hb_forward (v2), + impl (std::forward (v1), + std::forward (v2), hb_prioritize) ) } @@ -518,21 +518,21 @@ struct { template constexpr auto operator () (T&& a, T2&& b) const HB_AUTO_RETURN - (a <= b ? hb_forward (a) : hb_forward (b)) + (a <= b ? std::forward (a) : std::forward (b)) } HB_FUNCOBJ (hb_min); struct { template constexpr auto operator () (T&& a, T2&& b) const HB_AUTO_RETURN - (a >= b ? hb_forward (a) : hb_forward (b)) + (a >= b ? std::forward (a) : std::forward (b)) } HB_FUNCOBJ (hb_max); struct { template constexpr auto operator () (T&& x, T2&& min, T3&& max) const HB_AUTO_RETURN - (hb_min (hb_max (hb_forward (x), hb_forward (min)), hb_forward (max))) + (hb_min (hb_max (std::forward (x), std::forward (min)), std::forward (max))) } HB_FUNCOBJ (hb_clamp); diff --git a/src/hb-debug.hh b/src/hb-debug.hh index f80c8980b..3ac7440e8 100644 --- a/src/hb-debug.hh +++ b/src/hb-debug.hh @@ -302,7 +302,7 @@ struct hb_auto_trace_t { if (unlikely (returned)) { fprintf (stderr, "OUCH, double calls to return_trace(). This is a bug, please report.\n"); - return hb_forward (v); + return std::forward (v); } _hb_debug_msg (what, obj, func, true, plevel ? *plevel : 1, -1, @@ -311,7 +311,7 @@ struct hb_auto_trace_t if (plevel) --*plevel; plevel = nullptr; returned = true; - return hb_forward (v); + return std::forward (v); } private: @@ -333,7 +333,7 @@ struct hb_auto_trace_t<0, ret_t> template T ret (T&& v, const char *func HB_UNUSED = nullptr, - unsigned int line HB_UNUSED = 0) { return hb_forward (v); } + unsigned int line HB_UNUSED = 0) { return std::forward (v); } }; /* For disabled tracing; optimize out everything. @@ -343,7 +343,7 @@ struct hb_no_trace_t { template T ret (T&& v, const char *func HB_UNUSED = nullptr, - unsigned int line HB_UNUSED = 0) { return hb_forward (v); } + unsigned int line HB_UNUSED = 0) { return std::forward (v); } }; #define return_trace(RET) return trace.ret (RET, HB_FUNC, __LINE__) diff --git a/src/hb-dispatch.hh b/src/hb-dispatch.hh index 4b2b65a8d..37ca68146 100644 --- a/src/hb-dispatch.hh +++ b/src/hb-dispatch.hh @@ -50,7 +50,7 @@ struct hb_dispatch_context_t bool may_dispatch (const T *obj HB_UNUSED, const F *format HB_UNUSED) { return true; } template return_t dispatch (const T &obj, Ts&&... ds) - { return obj.dispatch (thiz (), hb_forward (ds)...); } + { return obj.dispatch (thiz (), std::forward (ds)...); } static return_t no_dispatch_return_value () { return Context::default_return_value (); } static bool stop_sublookup_iteration (const return_t r HB_UNUSED) { return false; } unsigned debug_depth = 0; diff --git a/src/hb-iter.hh b/src/hb-iter.hh index b8c447263..87b8ed880 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -162,7 +162,7 @@ struct { template hb_iter_type operator () (T&& c) const - { return hb_deref (hb_forward (c)).iter (); } + { return hb_deref (std::forward (c)).iter (); } /* Specialization for C arrays. */ @@ -353,7 +353,7 @@ static inline auto end (Iterable&& iterable) HB_AUTO_RETURN (hb_iter (iterable). template static inline auto -operator | (Lhs&& lhs, Rhs&& rhs) HB_AUTO_RETURN (hb_forward (rhs) (hb_forward (lhs))) +operator | (Lhs&& lhs, Rhs&& rhs) HB_AUTO_RETURN (std::forward (rhs) (std::forward (lhs))) /* hb_map(), hb_filter(), hb_reduce() */ @@ -674,8 +674,8 @@ struct hb_iota_iter_t : template auto inc (hb_type_identity s, hb_priority<1>) - -> hb_void_t (s), hb_declval ()))> - { v = hb_invoke (hb_forward (s), v); } + -> hb_void_t (s), hb_declval ()))> + { v = hb_invoke (std::forward (s), v); } void inc (S s, hb_priority<0>) @@ -874,7 +874,7 @@ struct Proj&& f = hb_identity) const { for (auto it = hb_iter (c); it; ++it) - if (!hb_match (hb_forward (p), hb_get (hb_forward (f), *it))) + if (!hb_match (std::forward (p), hb_get (std::forward (f), *it))) return false; return true; } @@ -891,7 +891,7 @@ struct Proj&& f = hb_identity) const { for (auto it = hb_iter (c); it; ++it) - if (hb_match (hb_forward (p), hb_get (hb_forward (f), *it))) + if (hb_match (std::forward (p), hb_get (std::forward (f), *it))) return true; return false; } @@ -908,7 +908,7 @@ struct Proj&& f = hb_identity) const { for (auto it = hb_iter (c); it; ++it) - if (hb_match (hb_forward (p), hb_get (hb_forward (f), *it))) + if (hb_match (std::forward (p), hb_get (std::forward (f), *it))) return false; return true; } diff --git a/src/hb-meta.hh b/src/hb-meta.hh index a2c32003b..2a6f90a43 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -175,17 +175,11 @@ using hb_is_cr_convertible = hb_bool_constant< >; #define hb_is_cr_convertible(From,To) hb_is_cr_convertible::value -/* std::forward */ - -template -static constexpr T&& hb_forward (hb_remove_reference& t) { return (T&&) t; } -template -static constexpr T&& hb_forward (hb_remove_reference&& t) { return (T&&) t; } struct { template constexpr auto - operator () (T&& v) const HB_AUTO_RETURN (hb_forward (v)) + operator () (T&& v) const HB_AUTO_RETURN (std::forward (v)) template constexpr auto operator () (T *v) const HB_AUTO_RETURN (*v) @@ -195,7 +189,7 @@ HB_FUNCOBJ (hb_deref); struct { template constexpr auto - operator () (T&& v) const HB_AUTO_RETURN (hb_forward (v)) + operator () (T&& v) const HB_AUTO_RETURN (std::forward (v)) template constexpr auto operator () (T& v) const HB_AUTO_RETURN (hb_addressof (v)) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 129aa868d..d3712f045 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -341,7 +341,7 @@ struct OffsetTo : Offset s->push (); - bool ret = c->dispatch (src_base+src, hb_forward (ds)...); + bool ret = c->dispatch (src_base+src, std::forward (ds)...); if (ret || !has_null) s->add_link (*this, s->pop_pack ()); @@ -358,7 +358,7 @@ struct OffsetTo : Offset *this = 0; Type* obj = c->push (); - bool ret = obj->serialize (c, hb_forward (ds)...); + bool ret = obj->serialize (c, std::forward (ds)...); if (ret) c->add_link (*this, c->pop_pack ()); @@ -384,7 +384,7 @@ struct OffsetTo : Offset c->push (); - bool ret = c->copy (src_base+src, hb_forward (ds)...); + bool ret = c->copy (src_base+src, std::forward (ds)...); c->add_link (*this, c->pop_pack (), whence, dst_bias); @@ -410,7 +410,7 @@ struct OffsetTo : Offset TRACE_SANITIZE (this); return_trace (sanitize_shallow (c, base) && (this->is_null () || - c->dispatch (StructAtOffset (base, *this), hb_forward (ds)...) || + c->dispatch (StructAtOffset (base, *this), std::forward (ds)...) || neuter (c))); } @@ -520,7 +520,7 @@ struct UnsizedArrayOf if (unlikely (!sanitize_shallow (c, count))) return_trace (false); if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); for (unsigned int i = 0; i < count; i++) - if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) + if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) return_trace (false); return_trace (true); } @@ -565,7 +565,7 @@ struct UnsizedListOfOffset16To : UnsizedArray16OfOffsetTo - ::sanitize (c, count, this, hb_forward (ds)...))); + ::sanitize (c, count, this, std::forward (ds)...))); } }; @@ -710,7 +710,7 @@ struct ArrayOf if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = len; for (unsigned int i = 0; i < count; i++) - if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) + if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) return_trace (false); return_trace (true); } @@ -768,7 +768,7 @@ struct List16OfOffset16To : Array16OfOffset16To bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const { TRACE_SANITIZE (this); - return_trace (Array16OfOffset16To::sanitize (c, this, hb_forward (ds)...)); + return_trace (Array16OfOffset16To::sanitize (c, this, std::forward (ds)...)); } }; @@ -838,7 +838,7 @@ struct HeadlessArrayOf if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = get_length (); for (unsigned int i = 0; i < count; i++) - if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) + if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) return_trace (false); return_trace (true); } @@ -887,7 +887,7 @@ struct ArrayOfM1 if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = lenM1 + 1; for (unsigned int i = 0; i < count; i++) - if (unlikely (!c->dispatch (arrayZ[i], hb_forward (ds)...))) + if (unlikely (!c->dispatch (arrayZ[i], std::forward (ds)...))) return_trace (false); return_trace (true); } @@ -1073,7 +1073,7 @@ struct VarSizedBinSearchArrayOf if (!sizeof... (Ts) && std::is_trivially_copyable::value) return_trace (true); unsigned int count = get_length (); for (unsigned int i = 0; i < count; i++) - if (unlikely (!(*this)[i].sanitize (c, hb_forward (ds)...))) + if (unlikely (!(*this)[i].sanitize (c, std::forward (ds)...))) return_trace (false); return_trace (true); } diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index eaaf5e12e..180c87cb8 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -373,7 +373,7 @@ struct Dict : UnsizedByteStr { TRACE_SERIALIZE (this); for (unsigned int i = 0; i < dictval.get_count (); i++) - if (unlikely (!opszr.serialize (c, dictval[i], hb_forward (ds)...))) + if (unlikely (!opszr.serialize (c, dictval[i], std::forward (ds)...))) return_trace (false); return_trace (true); diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index 9f34e56fb..936ea0b99 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -925,8 +925,8 @@ struct ClipBox TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1065,38 +1065,38 @@ struct Paint TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.paintformat1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.paintformat2, hb_forward (ds)...)); - case 3: return_trace (c->dispatch (u.paintformat3, hb_forward (ds)...)); - case 4: return_trace (c->dispatch (u.paintformat4, hb_forward (ds)...)); - case 5: return_trace (c->dispatch (u.paintformat5, hb_forward (ds)...)); - case 6: return_trace (c->dispatch (u.paintformat6, hb_forward (ds)...)); - case 7: return_trace (c->dispatch (u.paintformat7, hb_forward (ds)...)); - case 8: return_trace (c->dispatch (u.paintformat8, hb_forward (ds)...)); - case 9: return_trace (c->dispatch (u.paintformat9, hb_forward (ds)...)); - case 10: return_trace (c->dispatch (u.paintformat10, hb_forward (ds)...)); - case 11: return_trace (c->dispatch (u.paintformat11, hb_forward (ds)...)); - case 12: return_trace (c->dispatch (u.paintformat12, hb_forward (ds)...)); - case 13: return_trace (c->dispatch (u.paintformat13, hb_forward (ds)...)); - case 14: return_trace (c->dispatch (u.paintformat14, hb_forward (ds)...)); - case 15: return_trace (c->dispatch (u.paintformat15, hb_forward (ds)...)); - case 16: return_trace (c->dispatch (u.paintformat16, hb_forward (ds)...)); - case 17: return_trace (c->dispatch (u.paintformat17, hb_forward (ds)...)); - case 18: return_trace (c->dispatch (u.paintformat18, hb_forward (ds)...)); - case 19: return_trace (c->dispatch (u.paintformat19, hb_forward (ds)...)); - case 20: return_trace (c->dispatch (u.paintformat20, hb_forward (ds)...)); - case 21: return_trace (c->dispatch (u.paintformat21, hb_forward (ds)...)); - case 22: return_trace (c->dispatch (u.paintformat22, hb_forward (ds)...)); - case 23: return_trace (c->dispatch (u.paintformat23, hb_forward (ds)...)); - case 24: return_trace (c->dispatch (u.paintformat24, hb_forward (ds)...)); - case 25: return_trace (c->dispatch (u.paintformat25, hb_forward (ds)...)); - case 26: return_trace (c->dispatch (u.paintformat26, hb_forward (ds)...)); - case 27: return_trace (c->dispatch (u.paintformat27, hb_forward (ds)...)); - case 28: return_trace (c->dispatch (u.paintformat28, hb_forward (ds)...)); - case 29: return_trace (c->dispatch (u.paintformat29, hb_forward (ds)...)); - case 30: return_trace (c->dispatch (u.paintformat30, hb_forward (ds)...)); - case 31: return_trace (c->dispatch (u.paintformat31, hb_forward (ds)...)); - case 32: return_trace (c->dispatch (u.paintformat32, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.paintformat1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.paintformat2, std::forward (ds)...)); + case 3: return_trace (c->dispatch (u.paintformat3, std::forward (ds)...)); + case 4: return_trace (c->dispatch (u.paintformat4, std::forward (ds)...)); + case 5: return_trace (c->dispatch (u.paintformat5, std::forward (ds)...)); + case 6: return_trace (c->dispatch (u.paintformat6, std::forward (ds)...)); + case 7: return_trace (c->dispatch (u.paintformat7, std::forward (ds)...)); + case 8: return_trace (c->dispatch (u.paintformat8, std::forward (ds)...)); + case 9: return_trace (c->dispatch (u.paintformat9, std::forward (ds)...)); + case 10: return_trace (c->dispatch (u.paintformat10, std::forward (ds)...)); + case 11: return_trace (c->dispatch (u.paintformat11, std::forward (ds)...)); + case 12: return_trace (c->dispatch (u.paintformat12, std::forward (ds)...)); + case 13: return_trace (c->dispatch (u.paintformat13, std::forward (ds)...)); + case 14: return_trace (c->dispatch (u.paintformat14, std::forward (ds)...)); + case 15: return_trace (c->dispatch (u.paintformat15, std::forward (ds)...)); + case 16: return_trace (c->dispatch (u.paintformat16, std::forward (ds)...)); + case 17: return_trace (c->dispatch (u.paintformat17, std::forward (ds)...)); + case 18: return_trace (c->dispatch (u.paintformat18, std::forward (ds)...)); + case 19: return_trace (c->dispatch (u.paintformat19, std::forward (ds)...)); + case 20: return_trace (c->dispatch (u.paintformat20, std::forward (ds)...)); + case 21: return_trace (c->dispatch (u.paintformat21, std::forward (ds)...)); + case 22: return_trace (c->dispatch (u.paintformat22, std::forward (ds)...)); + case 23: return_trace (c->dispatch (u.paintformat23, std::forward (ds)...)); + case 24: return_trace (c->dispatch (u.paintformat24, std::forward (ds)...)); + case 25: return_trace (c->dispatch (u.paintformat25, std::forward (ds)...)); + case 26: return_trace (c->dispatch (u.paintformat26, std::forward (ds)...)); + case 27: return_trace (c->dispatch (u.paintformat27, std::forward (ds)...)); + case 28: return_trace (c->dispatch (u.paintformat28, std::forward (ds)...)); + case 29: return_trace (c->dispatch (u.paintformat29, std::forward (ds)...)); + case 30: return_trace (c->dispatch (u.paintformat30, std::forward (ds)...)); + case 31: return_trace (c->dispatch (u.paintformat31, std::forward (ds)...)); + case 32: return_trace (c->dispatch (u.paintformat32, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } diff --git a/src/hb-ot-kern-table.hh b/src/hb-ot-kern-table.hh index 3563cab8b..ffa11bc24 100644 --- a/src/hb-ot-kern-table.hh +++ b/src/hb-ot-kern-table.hh @@ -134,11 +134,11 @@ struct KernSubTable switch (subtable_type) { case 0: return_trace (c->dispatch (u.format0)); #ifndef HB_NO_AAT_SHAPE - case 1: return_trace (u.header.apple ? c->dispatch (u.format1, hb_forward (ds)...) : c->default_return_value ()); + case 1: return_trace (u.header.apple ? c->dispatch (u.format1, std::forward (ds)...) : c->default_return_value ()); #endif case 2: return_trace (c->dispatch (u.format2)); #ifndef HB_NO_AAT_SHAPE - case 3: return_trace (u.header.apple ? c->dispatch (u.format3, hb_forward (ds)...) : c->default_return_value ()); + case 3: return_trace (u.header.apple ? c->dispatch (u.format3, std::forward (ds)...) : c->default_return_value ()); #endif default: return_trace (c->default_return_value ()); } @@ -325,9 +325,9 @@ struct kern unsigned int subtable_type = get_type (); TRACE_DISPATCH (this, subtable_type); switch (subtable_type) { - case 0: return_trace (c->dispatch (u.ot, hb_forward (ds)...)); + case 0: return_trace (c->dispatch (u.ot, std::forward (ds)...)); #ifndef HB_NO_AAT_SHAPE - case 1: return_trace (c->dispatch (u.aat, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.aat, std::forward (ds)...)); #endif default: return_trace (c->default_return_value ()); } diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 87ac8781d..a43f5f8c0 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -1286,7 +1286,7 @@ struct Lookup TRACE_DISPATCH (this, lookup_type); unsigned int count = get_subtable_count (); for (unsigned int i = 0; i < count; i++) { - typename context_t::return_t r = get_subtable (i).dispatch (c, lookup_type, hb_forward (ds)...); + typename context_t::return_t r = get_subtable (i).dispatch (c, lookup_type, std::forward (ds)...); if (c->stop_sublookup_iteration (r)) return_trace (r); } @@ -2984,7 +2984,7 @@ struct Condition TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } diff --git a/src/hb-ot-layout-gdef-table.hh b/src/hb-ot-layout-gdef-table.hh index 31a4a3e84..41c5a1e1a 100644 --- a/src/hb-ot-layout-gdef-table.hh +++ b/src/hb-ot-layout-gdef-table.hh @@ -248,9 +248,9 @@ struct CaretValue TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); - case 3: return_trace (c->dispatch (u.format3, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 3: return_trace (c->dispatch (u.format3, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index ac8f6eaf8..a8fb5c7ac 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -1050,8 +1050,8 @@ struct SinglePos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1702,8 +1702,8 @@ struct PairPos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1959,7 +1959,7 @@ struct CursivePos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -2194,7 +2194,7 @@ struct MarkBasePos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -2434,7 +2434,7 @@ struct MarkLigPos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -2653,7 +2653,7 @@ struct MarkMarkPos TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -2704,15 +2704,15 @@ struct PosLookupSubTable { TRACE_DISPATCH (this, lookup_type); switch (lookup_type) { - case Single: return_trace (u.single.dispatch (c, hb_forward (ds)...)); - case Pair: return_trace (u.pair.dispatch (c, hb_forward (ds)...)); - case Cursive: return_trace (u.cursive.dispatch (c, hb_forward (ds)...)); - case MarkBase: return_trace (u.markBase.dispatch (c, hb_forward (ds)...)); - case MarkLig: return_trace (u.markLig.dispatch (c, hb_forward (ds)...)); - case MarkMark: return_trace (u.markMark.dispatch (c, hb_forward (ds)...)); - case Context: return_trace (u.context.dispatch (c, hb_forward (ds)...)); - case ChainContext: return_trace (u.chainContext.dispatch (c, hb_forward (ds)...)); - case Extension: return_trace (u.extension.dispatch (c, hb_forward (ds)...)); + case Single: return_trace (u.single.dispatch (c, std::forward (ds)...)); + case Pair: return_trace (u.pair.dispatch (c, std::forward (ds)...)); + case Cursive: return_trace (u.cursive.dispatch (c, std::forward (ds)...)); + case MarkBase: return_trace (u.markBase.dispatch (c, std::forward (ds)...)); + case MarkLig: return_trace (u.markLig.dispatch (c, std::forward (ds)...)); + case MarkMark: return_trace (u.markMark.dispatch (c, std::forward (ds)...)); + case Context: return_trace (u.context.dispatch (c, std::forward (ds)...)); + case ChainContext: return_trace (u.chainContext.dispatch (c, std::forward (ds)...)); + case Extension: return_trace (u.extension.dispatch (c, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } @@ -2800,7 +2800,7 @@ struct PosLookup : Lookup template typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const - { return Lookup::dispatch (c, hb_forward (ds)...); } + { return Lookup::dispatch (c, std::forward (ds)...); } bool subset (hb_subset_context_t *c) const { return Lookup::subset (c); } diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 55edfd4da..0dcc98cc0 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -290,8 +290,8 @@ struct SingleSubst TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -524,7 +524,7 @@ struct MultipleSubst TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -767,7 +767,7 @@ struct AlternateSubst TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1152,7 +1152,7 @@ struct LigatureSubst TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1395,7 +1395,7 @@ struct ReverseChainSingleSubst TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -1434,14 +1434,14 @@ struct SubstLookupSubTable { TRACE_DISPATCH (this, lookup_type); switch (lookup_type) { - case Single: return_trace (u.single.dispatch (c, hb_forward (ds)...)); - case Multiple: return_trace (u.multiple.dispatch (c, hb_forward (ds)...)); - case Alternate: return_trace (u.alternate.dispatch (c, hb_forward (ds)...)); - case Ligature: return_trace (u.ligature.dispatch (c, hb_forward (ds)...)); - case Context: return_trace (u.context.dispatch (c, hb_forward (ds)...)); - case ChainContext: return_trace (u.chainContext.dispatch (c, hb_forward (ds)...)); - case Extension: return_trace (u.extension.dispatch (c, hb_forward (ds)...)); - case ReverseChainSingle: return_trace (u.reverseChainContextSingle.dispatch (c, hb_forward (ds)...)); + case Single: return_trace (u.single.dispatch (c, std::forward (ds)...)); + case Multiple: return_trace (u.multiple.dispatch (c, std::forward (ds)...)); + case Alternate: return_trace (u.alternate.dispatch (c, std::forward (ds)...)); + case Ligature: return_trace (u.ligature.dispatch (c, std::forward (ds)...)); + case Context: return_trace (u.context.dispatch (c, std::forward (ds)...)); + case ChainContext: return_trace (u.chainContext.dispatch (c, std::forward (ds)...)); + case Extension: return_trace (u.extension.dispatch (c, std::forward (ds)...)); + case ReverseChainSingle: return_trace (u.reverseChainContextSingle.dispatch (c, std::forward (ds)...)); default: return_trace (c->default_return_value ()); } } @@ -1667,7 +1667,7 @@ struct SubstLookup : Lookup template typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const - { return Lookup::dispatch (c, hb_forward (ds)...); } + { return Lookup::dispatch (c, std::forward (ds)...); } bool subset (hb_subset_context_t *c) const { return Lookup::subset (c); } diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 9b958a8c6..fde273e69 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -2288,9 +2288,9 @@ struct Context TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); - case 3: return_trace (c->dispatch (u.format3, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 3: return_trace (c->dispatch (u.format3, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -3358,9 +3358,9 @@ struct ChainContext TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, hb_forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, hb_forward (ds)...)); - case 3: return_trace (c->dispatch (u.format3, hb_forward (ds)...)); + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + case 3: return_trace (c->dispatch (u.format3, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } @@ -3389,7 +3389,7 @@ struct ExtensionFormat1 { TRACE_DISPATCH (this, format); if (unlikely (!c->may_dispatch (this, this))) return_trace (c->no_dispatch_return_value ()); - return_trace (get_subtable ().dispatch (c, get_type (), hb_forward (ds)...)); + return_trace (get_subtable ().dispatch (c, get_type (), std::forward (ds)...)); } void collect_variation_indices (hb_collect_variation_indices_context_t *c) const @@ -3469,7 +3469,7 @@ struct Extension TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ()); switch (u.format) { - case 1: return_trace (u.format1.dispatch (c, hb_forward (ds)...)); + case 1: return_trace (u.format1.dispatch (c, std::forward (ds)...)); default:return_trace (c->default_return_value ()); } } diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index cf3e1df96..d02a3c0ea 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -2011,14 +2011,14 @@ struct hb_get_glyph_alternates_dispatch_t : private: template auto _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN - ( obj.get_glyph_alternates (hb_forward (ds)...) ) + ( obj.get_glyph_alternates (std::forward (ds)...) ) template auto _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN ( default_return_value () ) public: template auto dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN - ( _dispatch (obj, hb_prioritize, hb_forward (ds)...) ) + ( _dispatch (obj, hb_prioritize, std::forward (ds)...) ) }; /** diff --git a/src/hb-sanitize.hh b/src/hb-sanitize.hh index 56c46015a..2e536c7a8 100644 --- a/src/hb-sanitize.hh +++ b/src/hb-sanitize.hh @@ -145,14 +145,14 @@ struct hb_sanitize_context_t : private: template auto _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN - ( obj.sanitize (this, hb_forward (ds)...) ) + ( obj.sanitize (this, std::forward (ds)...) ) template auto _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN - ( obj.dispatch (this, hb_forward (ds)...) ) + ( obj.dispatch (this, std::forward (ds)...) ) public: template auto dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN - ( _dispatch (obj, hb_prioritize, hb_forward (ds)...) ) + ( _dispatch (obj, hb_prioritize, std::forward (ds)...) ) void init (hb_blob_t *b) diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 7212d9872..77bad06b8 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -189,8 +189,8 @@ struct hb_serialize_context_t { return check_success (!hb_deref (obj).in_error ()); } template bool propagate_error (T1 &&o1, Ts&&... os) - { return propagate_error (hb_forward (o1)) && - propagate_error (hb_forward (os)...); } + { return propagate_error (std::forward (o1)) && + propagate_error (std::forward (os)...); } /* To be called around main operation. */ template @@ -494,7 +494,7 @@ struct hb_serialize_context_t template auto _copy (const Type &src, hb_priority<1>, Ts&&... ds) HB_RETURN - (Type *, src.copy (this, hb_forward (ds)...)) + (Type *, src.copy (this, std::forward (ds)...)) template auto _copy (const Type &src, hb_priority<0>) -> decltype (&(hb_declval () = src)) @@ -509,16 +509,16 @@ struct hb_serialize_context_t * instead of memcpy(). */ template Type *copy (const Type &src, Ts&&... ds) - { return _copy (src, hb_prioritize, hb_forward (ds)...); } + { return _copy (src, hb_prioritize, std::forward (ds)...); } template Type *copy (const Type *src, Ts&&... ds) - { return copy (*src, hb_forward (ds)...); } + { return copy (*src, std::forward (ds)...); } template void copy_all (Iterator it, Ts&&... ds) - { for (decltype (*it) _ : it) copy (_, hb_forward (ds)...); } + { for (decltype (*it) _ : it) copy (_, std::forward (ds)...); } template hb_serialize_context_t& operator << (const Type &obj) & { embed (obj); return *this; } @@ -546,10 +546,10 @@ struct hb_serialize_context_t template Type *extend (Type *obj, Ts&&... ds) - { return extend_size (obj, obj->get_size (hb_forward (ds)...)); } + { return extend_size (obj, obj->get_size (std::forward (ds)...)); } template Type *extend (Type &obj, Ts&&... ds) - { return extend (hb_addressof (obj), hb_forward (ds)...); } + { return extend (hb_addressof (obj), std::forward (ds)...); } /* Output routines. */ hb_bytes_t copy_bytes () const diff --git a/src/hb-subset.hh b/src/hb-subset.hh index c9b01c67f..98c5f06fb 100644 --- a/src/hb-subset.hh +++ b/src/hb-subset.hh @@ -45,14 +45,14 @@ struct hb_subset_context_t : private: template auto _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN - ( obj.subset (this, hb_forward (ds)...) ) + ( obj.subset (this, std::forward (ds)...) ) template auto _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN - ( obj.dispatch (this, hb_forward (ds)...) ) + ( obj.dispatch (this, std::forward (ds)...) ) public: template auto dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN - ( _dispatch (obj, hb_prioritize, hb_forward (ds)...) ) + ( _dispatch (obj, hb_prioritize, std::forward (ds)...) ) hb_blob_t *source_blob; hb_subset_plan_t *plan; diff --git a/src/hb-vector.hh b/src/hb-vector.hh index df6b08628..b0a1e5e96 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -150,7 +150,7 @@ struct hb_vector_t /* Sink interface. */ template - hb_vector_t& operator << (T&& v) { push (hb_forward (v)); return *this; } + hb_vector_t& operator << (T&& v) { push (std::forward (v)); return *this; } hb_array_t< Type> as_array () { return hb_array (arrayZ, length); } hb_array_t as_array () const { return hb_array (arrayZ, length); } @@ -198,7 +198,7 @@ struct hb_vector_t // the created copy to leak memory since we won't have stored a // reference to it. return p; - *p = hb_forward (v); + *p = std::forward (v); return p; } From 943921cf0caefa564601f7b18eed2168be77cfda Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 2 Nov 2021 00:26:46 -0600 Subject: [PATCH 29/32] [meta] Use more std type_traits --- src/hb-algs.hh | 6 +++--- src/hb-map.hh | 8 ++++---- src/hb-meta.hh | 44 -------------------------------------------- src/hb-open-type.hh | 4 ++-- src/hb-serialize.hh | 2 +- src/test-meta.cc | 3 --- 6 files changed, 10 insertions(+), 57 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 55c92841f..446d87e28 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -128,7 +128,7 @@ struct BEInt template struct BEInt { - static_assert (!hb_is_signed (Type), ""); + static_assert (!std::is_signed::value, ""); public: BEInt () = default; constexpr BEInt (Type V) : v {uint8_t ((V >> 16) & 0xFF), @@ -218,7 +218,7 @@ struct impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, hb_deref (v).hash ()) template constexpr auto + hb_enable_if (std::is_integral::value)> constexpr auto impl (const T& v, hb_priority<0>) const HB_AUTO_RETURN ( /* Knuth's multiplicative method: */ @@ -808,7 +808,7 @@ hb_ceil_to_4 (unsigned int v) template static inline bool hb_in_range (T u, T lo, T hi) { - static_assert (!hb_is_signed::value, ""); + static_assert (!std::is_signed::value, ""); /* The casts below are important as if T is smaller than int, * the subtract results will become a signed int! */ diff --git a/src/hb-map.hh b/src/hb-map.hh index c14a52af0..790457f26 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -35,8 +35,8 @@ */ template + K kINVALID = hb_is_pointer (K) ? 0 : std::is_signed::value ? hb_int_min (K) : (K) -1, + V vINVALID = hb_is_pointer (V) ? 0 : std::is_signed::value ? hb_int_min (V) : (V) -1> struct hb_hashmap_t { hb_hashmap_t () { init (); } @@ -59,8 +59,8 @@ struct hb_hashmap_t hb_copy (o, *this); } - static_assert (hb_is_integral (K) || hb_is_pointer (K), ""); - static_assert (hb_is_integral (V) || hb_is_pointer (V), ""); + static_assert (std::is_integral::value || hb_is_pointer (K), ""); + static_assert (std::is_integral::value || hb_is_pointer (V), ""); struct item_t { diff --git a/src/hb-meta.hh b/src/hb-meta.hh index 2a6f90a43..3808d917b 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -220,50 +220,6 @@ struct hb_reference_wrapper /* Type traits */ -template -using hb_is_integral = hb_bool_constant< - hb_is_same (hb_decay, char) || - hb_is_same (hb_decay, signed char) || - hb_is_same (hb_decay, unsigned char) || - hb_is_same (hb_decay, signed int) || - hb_is_same (hb_decay, unsigned int) || - hb_is_same (hb_decay, signed short) || - hb_is_same (hb_decay, unsigned short) || - hb_is_same (hb_decay, signed long) || - hb_is_same (hb_decay, unsigned long) || - hb_is_same (hb_decay, signed long long) || - hb_is_same (hb_decay, unsigned long long) || - false ->; -#define hb_is_integral(T) hb_is_integral::value -template -using hb_is_floating_point = hb_bool_constant< - hb_is_same (hb_decay, float) || - hb_is_same (hb_decay, double) || - hb_is_same (hb_decay, long double) || - false ->; -#define hb_is_floating_point(T) hb_is_floating_point::value -template -using hb_is_arithmetic = hb_bool_constant< - hb_is_integral (T) || - hb_is_floating_point (T) || - false ->; -#define hb_is_arithmetic(T) hb_is_arithmetic::value - - -template struct hb_is_signed_; -template struct hb_is_signed_ : hb_false_type {}; -template struct hb_is_signed_ : hb_bool_constant<(T) -1 < (T) 0> {}; -template struct hb_is_signed : hb_is_signed_ {}; -#define hb_is_signed(T) hb_is_signed::value -template struct hb_is_unsigned_; -template struct hb_is_unsigned_ : hb_false_type {}; -template struct hb_is_unsigned_ : hb_bool_constant<(T) 0 < (T) -1> {}; -template struct hb_is_unsigned : hb_is_unsigned_ {}; -#define hb_is_unsigned(T) hb_is_unsigned::value - template struct hb_int_min; template <> struct hb_int_min : hb_integral_constant {}; template <> struct hb_int_min : hb_integral_constant {}; diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index d3712f045..1504584f1 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -64,7 +64,7 @@ struct IntType IntType& operator = (Type i) { v = i; return *this; } /* For reason we define cast out operator for signed/unsigned, instead of Type, see: * https://github.com/harfbuzz/harfbuzz/pull/2875/commits/09836013995cab2b9f07577a179ad7b024130467 */ - operator hb_conditional () const { return v; } + operator hb_conditional::value, signed, unsigned> () const { return v; } bool operator == (const IntType &o) const { return (Type) v == (Type) o.v; } bool operator != (const IntType &o) const { return !(*this == o); } @@ -86,7 +86,7 @@ struct IntType return pb->cmp (*pa); } template ::value && sizeof (Type2) < sizeof (int) && sizeof (Type) < sizeof (int))> int cmp (Type2 a) const diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 77bad06b8..7b83fe1a2 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -376,7 +376,7 @@ struct hb_serialize_context_t err (HB_SERIALIZE_ERROR_OTHER); link.width = sizeof (T); - link.is_signed = hb_is_signed (hb_unwrap_type (T)); + link.is_signed = std::is_signed::value; link.whence = (unsigned) whence; link.position = (const char *) &ofs - current->head; link.bias = bias; diff --git a/src/test-meta.cc b/src/test-meta.cc index c6715ac58..0fb2385af 100644 --- a/src/test-meta.cc +++ b/src/test-meta.cc @@ -95,9 +95,6 @@ main (int argc, char **argv) static_assert (hb_is_base_of (X, const Y), ""); static_assert (!hb_is_base_of (Y, X), ""); - static_assert (hb_is_signed (hb_unwrap_type (U>>)), ""); - static_assert (hb_is_unsigned (hb_unwrap_type (U>>>)), ""); - /* TODO Add more meaningful tests. */ return 0; From 7a078c395a57097a2ae204c0089f47a9ac97d849 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 2 Nov 2021 00:44:51 -0600 Subject: [PATCH 30/32] [meta] Use std::conditional instead of hb_conditional() --- src/hb-meta.hh | 13 ++----------- src/hb-open-type.hh | 2 +- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/hb-meta.hh b/src/hb-meta.hh index 3808d917b..4ec3702bf 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -132,15 +132,6 @@ template using hb_add_pointer = decltype (_hb_try_add_pointer (h /* TODO Add feature-parity to std::decay. */ template using hb_decay = hb_remove_const>; - -template -struct _hb_conditional { typedef T type; }; -template -struct _hb_conditional { typedef F type; }; -template -using hb_conditional = typename _hb_conditional::type; - - template struct hb_is_convertible { @@ -150,7 +141,7 @@ struct hb_is_convertible static constexpr bool either_void = from_void || to_void; static constexpr bool both_void = from_void && to_void; - static hb_true_type impl2 (hb_conditional); + static hb_true_type impl2 (typename std::conditional::type); template static auto impl (hb_priority<1>) -> decltype (impl2 (hb_declval (T))); @@ -159,7 +150,7 @@ struct hb_is_convertible public: static constexpr bool value = both_void || (!either_void && - decltype (impl> (hb_prioritize))::value); + decltype (impl::type> (hb_prioritize))::value); }; #define hb_is_convertible(From,To) hb_is_convertible::value diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 1504584f1..7e524177f 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -64,7 +64,7 @@ struct IntType IntType& operator = (Type i) { v = i; return *this; } /* For reason we define cast out operator for signed/unsigned, instead of Type, see: * https://github.com/harfbuzz/harfbuzz/pull/2875/commits/09836013995cab2b9f07577a179ad7b024130467 */ - operator hb_conditional::value, signed, unsigned> () const { return v; } + operator typename std::conditional::value, signed, unsigned>::type () const { return v; } bool operator == (const IntType &o) const { return (Type) v == (Type) o.v; } bool operator != (const IntType &o) const { return !(*this == o); } From b8724c60232a97d1e1785c3c618a340089be9c8a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 2 Nov 2021 00:49:40 -0600 Subject: [PATCH 31/32] [meta] Add in-house impl of hb_is_convertible() --- src/hb-meta.hh | 26 +------------------------- src/test-meta.cc | 14 -------------- 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/src/hb-meta.hh b/src/hb-meta.hh index 4ec3702bf..0ea5774a9 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -132,31 +132,7 @@ template using hb_add_pointer = decltype (_hb_try_add_pointer (h /* TODO Add feature-parity to std::decay. */ template using hb_decay = hb_remove_const>; -template -struct hb_is_convertible -{ - private: - static constexpr bool from_void = hb_is_same (void, hb_decay); - static constexpr bool to_void = hb_is_same (void, hb_decay ); - static constexpr bool either_void = from_void || to_void; - static constexpr bool both_void = from_void && to_void; - - static hb_true_type impl2 (typename std::conditional::type); - - template - static auto impl (hb_priority<1>) -> decltype (impl2 (hb_declval (T))); - template - static hb_false_type impl (hb_priority<0>); - public: - static constexpr bool value = both_void || - (!either_void && - decltype (impl::type> (hb_prioritize))::value); -}; -#define hb_is_convertible(From,To) hb_is_convertible::value - -template -using hb_is_base_of = hb_is_convertible *, hb_decay *>; -#define hb_is_base_of(Base,Derived) hb_is_base_of::value +#define hb_is_convertible(From,To) std::is_convertible::value template using hb_is_cr_convertible = hb_bool_constant< diff --git a/src/test-meta.cc b/src/test-meta.cc index 0fb2385af..ae9b56b8b 100644 --- a/src/test-meta.cc +++ b/src/test-meta.cc @@ -81,20 +81,6 @@ main (int argc, char **argv) static_assert (hb_is_convertible (int *, void *), ""); static_assert (!hb_is_convertible (void *, int *), ""); - static_assert (hb_is_base_of (void, void), ""); - static_assert (hb_is_base_of (void, int), ""); - static_assert (!hb_is_base_of (int, void), ""); - - static_assert (hb_is_base_of (int, int), ""); - static_assert (hb_is_base_of (const int, int), ""); - static_assert (hb_is_base_of (int, const int), ""); - - static_assert (hb_is_base_of (X, X), ""); - static_assert (hb_is_base_of (X, Y), ""); - static_assert (hb_is_base_of (const X, Y), ""); - static_assert (hb_is_base_of (X, const Y), ""); - static_assert (!hb_is_base_of (Y, X), ""); - /* TODO Add more meaningful tests. */ return 0; From 459e485babea657e47930e74bd56280658811af2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 2 Nov 2021 09:36:12 -0600 Subject: [PATCH 32/32] [meta] Remove otherwise-empty test-meta --- src/Makefile.am | 5 --- src/meson.build | 1 - src/test-meta.cc | 87 ------------------------------------------------ 3 files changed, 93 deletions(-) delete mode 100644 src/test-meta.cc diff --git a/src/Makefile.am b/src/Makefile.am index 1bccc5e96..c0c77055e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -347,7 +347,6 @@ COMPILED_TESTS = \ test-array \ test-iter \ test-map \ - test-meta \ test-number \ test-ot-tag \ test-priority-queue \ @@ -386,10 +385,6 @@ test_map_SOURCES = test-map.cc hb-static.cc test_map_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) test_map_LDADD = $(COMPILED_TESTS_LDADD) -test_meta_SOURCES = test-meta.cc hb-static.cc -test_meta_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) -test_meta_LDADD = $(COMPILED_TESTS_LDADD) - test_number_SOURCES = test-number.cc hb-number.cc test_number_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) test_number_LDADD = $(COMPILED_TESTS_LDADD) diff --git a/src/meson.build b/src/meson.build index 61b3dce0e..bda44c683 100644 --- a/src/meson.build +++ b/src/meson.build @@ -489,7 +489,6 @@ if get_option('tests').enabled() 'test-priority-queue': ['test-priority-queue.cc', 'hb-static.cc'], 'test-iter': ['test-iter.cc', 'hb-static.cc'], 'test-map': ['test-map.cc', 'hb-static.cc'], - 'test-meta': ['test-meta.cc', 'hb-static.cc'], 'test-number': ['test-number.cc', 'hb-number.cc'], 'test-ot-tag': ['hb-ot-tag.cc'], 'test-set': ['test-set.cc', 'hb-static.cc'], diff --git a/src/test-meta.cc b/src/test-meta.cc deleted file mode 100644 index ae9b56b8b..000000000 --- a/src/test-meta.cc +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright © 2019 Facebook, Inc. - * - * This is part of HarfBuzz, a text shaping library. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - * - * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN - * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * Facebook Author(s): Behdad Esfahbod - */ - -#include "hb.hh" -#include "hb-meta.hh" - -#include - -template struct U { typedef T type; }; - -int -main (int argc, char **argv) -{ - static_assert (hb_is_convertible (void, void), ""); - static_assert (hb_is_convertible (void, const void), ""); - static_assert (hb_is_convertible (const void, void), ""); - - static_assert (hb_is_convertible (int, int), ""); - static_assert (hb_is_convertible (char, int), ""); - static_assert (hb_is_convertible (long, int), ""); - - static_assert (hb_is_convertible (int, int), ""); - - static_assert (hb_is_convertible (const int, int), ""); - static_assert (hb_is_convertible (int, const int), ""); - static_assert (hb_is_convertible (const int, const int), ""); - - static_assert (hb_is_convertible (int&, int), ""); - static_assert (!hb_is_convertible (int, int&), ""); - - static_assert (hb_is_convertible (int, const int&), ""); - static_assert (!hb_is_convertible (const int, int&), ""); - static_assert (hb_is_convertible (const int, const int&), ""); - static_assert (hb_is_convertible (int&, const int), ""); - static_assert (hb_is_convertible (const int&, int), ""); - static_assert (hb_is_convertible (const int&, const int), ""); - static_assert (hb_is_convertible (const int&, const int), ""); - - struct X {}; - struct Y : X {}; - - static_assert (hb_is_convertible (const X &, const X), ""); - static_assert (hb_is_convertible (X &, const X), ""); - static_assert (hb_is_convertible (X &, const X &), ""); - static_assert (hb_is_convertible (X, const X &), ""); - static_assert (hb_is_convertible (const X, const X &), ""); - static_assert (!hb_is_convertible (const X, X &), ""); - static_assert (!hb_is_convertible (X, X &), ""); - static_assert (hb_is_convertible (X &, X &), ""); - - static_assert (hb_is_convertible (int&, long), ""); - static_assert (!hb_is_convertible (int&, long&), ""); - - static_assert (hb_is_convertible (int *, int *), ""); - static_assert (hb_is_convertible (int *, const int *), ""); - static_assert (!hb_is_convertible (const int *, int *), ""); - static_assert (!hb_is_convertible (int *, long *), ""); - static_assert (hb_is_convertible (int *, void *), ""); - static_assert (!hb_is_convertible (void *, int *), ""); - - /* TODO Add more meaningful tests. */ - - return 0; -}