Pre-allocate buffers when adding string
authorBehdad Esfahbod <behdad@behdad.org>
Mon, 15 Aug 2011 14:21:22 +0000 (16:21 +0200)
committerBehdad Esfahbod <behdad@behdad.org>
Mon, 15 Aug 2011 14:21:22 +0000 (16:21 +0200)
We do a conservative estimate of the number of characters, but still,
this limits the number of buffer reallocs to a small constant.

src/hb-buffer.cc

index 3be3f44..3f46d68 100644 (file)
@@ -723,6 +723,7 @@ hb_buffer_guess_properties (hb_buffer_t *buffer)
          } \
          if (item_length == -1) \
            item_length = text_length - item_offset; \
+         buffer->ensure (buffer->len + item_length * sizeof (T) / 4); \
          const T *next = (const T *) text + item_offset; \
          const T *end = next + item_length; \
          while (next < end) { \