[gtk/wip/baedert/for-master] gtkarray: memcpy() directly into the GPtrArray



commit 0cf93ffd1091d1e1174db7c677eadf5498fef5b0
Author: Timm Bäder <mail baedert org>
Date:   Wed May 6 10:25:05 2020 +0200

    gtkarray: memcpy() directly into the GPtrArray

 gtk/gtkarrayimplprivate.h | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkarrayimplprivate.h b/gtk/gtkarrayimplprivate.h
index 8a669f2a40..cd8051373d 100644
--- a/gtk/gtkarrayimplprivate.h
+++ b/gtk/gtkarrayimplprivate.h
@@ -55,13 +55,9 @@ gtk_array_add (GtkArray *self,
   /* Need to fall back to the GPtrArray */
   if (G_UNLIKELY (!self->ptr_array))
     {
-      guint i;
-
-      self->ptr_array = g_ptr_array_new_full (self->reserved_size, NULL);
-
-      /* Copy elements from stack space to GPtrArray */
-      for (i = 0; i < self->len; i++)
-        g_ptr_array_add (self->ptr_array, self->stack_space[i]);
+      self->ptr_array = g_ptr_array_new_full (self->len + 1, NULL);
+      memcpy (self->ptr_array->pdata, self->stack_space, sizeof (void *) * self->len);
+      self->ptr_array->len = self->len;
     }
 
   g_ptr_array_add (self->ptr_array, element);
@@ -90,12 +86,9 @@ gtk_array_insert (GtkArray *self,
 
   if (G_UNLIKELY (!self->ptr_array))
     {
-      guint i;
-
-      self->ptr_array = g_ptr_array_new_full (self->reserved_size, NULL);
-
-      for (i = 0; i < self->len; i++)
-        g_ptr_array_add (self->ptr_array, self->stack_space[i]);
+      self->ptr_array = g_ptr_array_new_full (self->len + 1, NULL);
+      memcpy (self->ptr_array->pdata, self->stack_space, sizeof (void *) * self->len);
+      self->ptr_array->len = self->len;
     }
 
   g_assert (self->ptr_array);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]