Allocate buffer->positions lazily.

2007-10-11  Behdad Esfahbod  <behdad@gnome.org>

        * pango/opentype/*: Allocate buffer->positions lazily.


diff --git a/src/harfbuzz-buffer.c b/src/harfbuzz-buffer.c
index f597ac9..e39a24b 100644
--- a/src/harfbuzz-buffer.c
+++ b/src/harfbuzz-buffer.c
@@ -51,10 +51,15 @@
       while (size > new_allocated)
 	new_allocated += (new_allocated >> 1) + 8;
       
-      if ( REALLOC_ARRAY( buffer->positions, new_allocated, HB_PositionRec ) )
-	return error;
+      if ( buffer->positions )
+        {
+	  if ( REALLOC_ARRAY( buffer->positions, new_allocated, HB_PositionRec ) )
+	    return error;
+	}
+
       if ( REALLOC_ARRAY( buffer->in_string, new_allocated, HB_GlyphItemRec ) )
 	return error;
+
       if ( buffer->inplace )
         {
 	  buffer->out_string = buffer->in_string;
@@ -121,6 +126,22 @@
   return HB_Err_Ok;
 }
 
+HB_Error
+hb_buffer_clear_positions( HB_Buffer buffer )
+{
+  if ( !buffer->positions )
+    {
+      HB_Error error;
+
+      if ( ALLOC_ARRAY( buffer->positions, buffer->allocated, HB_PositionRec ) )
+	return error;
+    }
+
+  memset (buffer->positions, 0, sizeof (buffer->positions[0]) * buffer->in_length);
+
+  return HB_Err_Ok;
+}
+
 void
 hb_buffer_clear_output( HB_Buffer buffer )
 {