emacs-diffs
[Top][All Lists]
Advanced

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

scratch/igc 64703cc8d92 1/2: Simplify face_cache and image_cache handlin


From: Gerd Moellmann
Subject: scratch/igc 64703cc8d92 1/2: Simplify face_cache and image_cache handling
Date: Mon, 29 Jul 2024 11:39:46 -0400 (EDT)

branch: scratch/igc
commit 64703cc8d922d1634e6223a20d50a768fc36315e
Author: Gerd Möllmann <gerd@gnu.org>
Commit: Gerd Möllmann <gerd@gnu.org>

    Simplify face_cache and image_cache handling
    
    * src/igc.c (obj_type_names): Remove IGC_OBJ_PTR_VEC.
    (object_nelems): Removed.
    (fix_image_cache, fix_face_cache): Fix images/faces.
    (fix_ptr_vec): Removed.
    (dflt_scan_obj, (thread_ap): Remove IGC_OBJ_PTR_VEC.
    (igc_make_ptr_vec, igc_grow_ptr_vec): Removed.
    * src/igc.h (IGC_OBJ_PTR_VEC): Removed.
    * src/image.c (make_image_cache, free_image_cache)
    (cache_image): Remove ptr_vec specific code.
    * src/xfaces.c (make_face_cache, free_face_cache)
    (cache_face): Remove ptr_vec specific code.
---
 src/igc.c    | 91 +++++++++++-------------------------------------------------
 src/igc.h    |  3 --
 src/image.c  | 13 ++-------
 src/xfaces.c | 11 +-------
 4 files changed, 20 insertions(+), 98 deletions(-)

diff --git a/src/igc.c b/src/igc.c
index 730179e1ab9..4a0810d9d73 100644
--- a/src/igc.c
+++ b/src/igc.c
@@ -349,7 +349,6 @@ static const char *obj_type_names[] = {
   "IGC_OBJ_FACE_CACHE",
   "IGC_OBJ_FLOAT",
   "IGC_OBJ_BLV",
-  "IGC_OBJ_PTR_VEC",
   "IGC_OBJ_HANDLER",
   "IGC_OBJ_BYTES",
   "IGC_OBJ_BUILTIN_SYMBOL",
@@ -686,15 +685,6 @@ void gc_init_header_bytes (union gc_header *header, enum 
igc_obj_type type,
     }
 }
 
-/* Given a client pointer CLIENT to an object, return how many
-   elements of size ELEM_SIZE can fit into the client area.  */
-
-static size_t
-object_nelems (struct igc_header *h, size_t elem_size)
-{
-  return (obj_client_size (h) - sizeof *h) / elem_size;
-}
-
 /* Round NBYTES to the next multiple of ALIGN.  */
 
 static size_t
@@ -1697,9 +1687,14 @@ fix_image_cache (mps_ss_t ss, struct image_cache *c)
   MPS_SCAN_BEGIN (ss)
   {
 #ifdef HAVE_WINDOW_SYSTEM
-
-    IGC_FIX12_WRAPPED_BYTES (ss, &c->images);
-    IGC_FIX12_WRAPPED_BYTES (ss, &c->buckets);
+    if (c->images)
+      for (ptrdiff_t i = 0; i < c->used; ++i)
+       IGC_FIX12_RAW (ss, &c->images[i]);
+
+    if (c->buckets)
+      for (ptrdiff_t i = 0; i < IMAGE_CACHE_BUCKETS_SIZE; ++i)
+       if (c->buckets[i])
+         IGC_FIX12_RAW (ss, &c->buckets[i]);
 #endif
   }
   MPS_SCAN_END (ss);
@@ -1730,22 +1725,15 @@ fix_face_cache (mps_ss_t ss, struct face_cache *c)
   MPS_SCAN_BEGIN (ss)
   {
     IGC_FIX12_PVEC (ss, &c->f);
-    IGC_FIX12_WRAPPED_BYTES (ss, &c->faces_by_id);
-    IGC_FIX12_WRAPPED_BYTES (ss, &c->buckets);
-  }
-  MPS_SCAN_END (ss);
-  return MPS_RES_OK;
-}
 
-static mps_res_t
-fix_ptr_vec (mps_ss_t ss, struct igc_header *h)
-{
-  MPS_SCAN_BEGIN (ss)
-  {
-    struct igc_header **v = (void *)(h + 1);
-    size_t n = object_nelems (h, sizeof *v);
-    for (size_t i = 0; i < n; ++i)
-      IGC_FIX12_RAW (ss, &v[i]);
+    if (c->faces_by_id)
+      for (ptrdiff_t i = 0; i < c->used; ++i)
+       IGC_FIX12_RAW (ss, &c->faces_by_id[i]);
+
+    if (c->buckets)
+      for (ptrdiff_t i = 0; i < FACE_CACHE_BUCKETS_SIZE; ++i)
+       if (c->buckets[i])
+         IGC_FIX12_RAW (ss, &c->buckets[i]);
   }
   MPS_SCAN_END (ss);
   return MPS_RES_OK;
@@ -1863,10 +1851,6 @@ dflt_scan_obj (mps_ss_t ss, mps_addr_t base_start, 
mps_addr_t base_limit,
        IGC_FIX_CALL_FN (ss, struct handler, client, fix_handler);
        break;
 
-      case IGC_OBJ_PTR_VEC:
-       IGC_FIX_CALL_FN (ss, struct igc_header, header, fix_ptr_vec);
-       break;
-
       case IGC_OBJ_CONS:
        IGC_FIX_CALL_FN (ss, struct Lisp_Cons, client, fix_cons);
        break;
@@ -3689,7 +3673,6 @@ thread_ap (enum igc_obj_type type)
     case IGC_OBJ_FACE:
     case IGC_OBJ_FACE_CACHE:
     case IGC_OBJ_BLV:
-    case IGC_OBJ_PTR_VEC:
     case IGC_OBJ_HANDLER:
       return t->d.dflt_ap;
 
@@ -4024,14 +4007,6 @@ igc_make_face_cache (void)
   return c;
 }
 
-void *
-igc_make_ptr_vec (size_t n)
-{
-  struct igc_header *ret =
-    alloc (sizeof (struct igc_header) + n * sizeof (void *), IGC_OBJ_PTR_VEC);
-  return ret + 1;
-}
-
 /* Allocate a Lisp_Object vector with N elements.
    Currently only used by SAFE_ALLOCA_LISP.  */
 
@@ -4172,40 +4147,6 @@ igc_alloc_weak_hash_table_weak_part 
(hash_table_weakness_t weak,
                IGC_OBJ_WEAK_HASH_TABLE_WEAK_PART);
 }
 
-/* Like xpalloc, but uses 'alloc' instead of xrealloc, and should only
-   be used for growing a vector of pointers whose current size is N
-   pointers.  */
-
-void *
-igc_grow_ptr_vec (void *v, ptrdiff_t *n, ptrdiff_t n_incr_min, ptrdiff_t n_max)
-{
-  const ptrdiff_t min_items = 16;
-  ptrdiff_t nitems0 = *n;
-  ptrdiff_t half_nitems0 = nitems0 / 2;
-  ptrdiff_t max_items = n_max < 0 ? PTRDIFF_MAX : n_max;
-  ptrdiff_t new_nitems;
-
-  if (half_nitems0 < n_incr_min)
-    half_nitems0 = n_incr_min;
-
-  if (nitems0 < min_items)
-    new_nitems = min_items;
-  else if (nitems0 < max_items - half_nitems0)
-    new_nitems = nitems0 + half_nitems0;
-  else
-    new_nitems = max_items;
-
-  if (new_nitems <= nitems0)
-    memory_full (0);
-
-  void *new_vec = igc_make_ptr_vec (new_nitems);
-  igc_assert (*n <= new_nitems);
-  igc_assert (new_nitems < PTRDIFF_MAX);
-  memcpy (new_vec, v, *n * sizeof (void *));
-  *n = new_nitems;
-  return new_vec;
-}
-
 #ifdef HAVE_WINDOW_SYSTEM
 struct image_cache *
 igc_make_image_cache (void)
diff --git a/src/igc.h b/src/igc.h
index 08867a9ed95..00e37b6c952 100644
--- a/src/igc.h
+++ b/src/igc.h
@@ -43,7 +43,6 @@ enum igc_obj_type
   IGC_OBJ_FACE_CACHE,
   IGC_OBJ_FLOAT,
   IGC_OBJ_BLV,
-  IGC_OBJ_PTR_VEC,
   IGC_OBJ_HANDLER,
   IGC_OBJ_BYTES,
   IGC_OBJ_BUILTIN_SYMBOL,
@@ -118,8 +117,6 @@ struct itree_tree *igc_make_itree_tree (void);
 struct image *igc_make_image (void);
 struct face *igc_make_face (void);
 struct face_cache *igc_make_face_cache (void);
-void *igc_make_ptr_vec (size_t n);
-void *igc_grow_ptr_vec (void *v, ptrdiff_t *n, ptrdiff_t n_incr_min, ptrdiff_t 
n_max);
 void igc_grow_rdstack (struct read_stack *rs);
 Lisp_Object *igc_make_hash_table_vec (size_t n);
 struct Lisp_Weak_Hash_Table_Strong_Part 
*igc_alloc_weak_hash_table_strong_part(hash_table_weakness_t, size_t, size_t);
diff --git a/src/image.c b/src/image.c
index 24a4e61a8da..04c7d43d488 100644
--- a/src/image.c
+++ b/src/image.c
@@ -2204,13 +2204,8 @@ make_image_cache (void)
 
   c->size = 50;
   c->used = c->refcount = 0;
-#ifdef HAVE_MPS
-  c->images = igc_make_ptr_vec (c->size);
-  c->buckets = igc_make_ptr_vec (IMAGE_CACHE_BUCKETS_SIZE);
-#else
   c->images = xmalloc (c->size * sizeof *c->images);
   c->buckets = xzalloc (IMAGE_CACHE_BUCKETS_SIZE * sizeof *c->buckets);
-#endif
   /* This value should never be encountered.  */
   c->scaling_col_width = -1;
   return c;
@@ -2327,9 +2322,11 @@ free_image_cache (struct frame *f)
 
   for (i = 0; i < c->used; ++i)
     free_image (f, c->images[i]);
-#ifndef HAVE_MPS
   xfree (c->images);
+  c->images = NULL;
   xfree (c->buckets);
+  c->buckets = NULL;
+#ifndef HAVE_MPS
   xfree (c);
 #endif
 }
@@ -3648,11 +3645,7 @@ cache_image (struct frame *f, struct image *img)
   /* If no free slot found, maybe enlarge c->images.  */
   if (i == c->used && c->used == c->size)
     {
-#ifdef HAVE_MPS
-      c->images = igc_grow_ptr_vec (c->images, &c->size, 1, -1);
-#else
       c->images = xpalloc (c->images, &c->size, 1, -1, sizeof *c->images);
-#endif
     }
 
   /* Add IMG to c->images, and assign IMG an id.  */
diff --git a/src/xfaces.c b/src/xfaces.c
index 650ab7635c2..69d4070b603 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -4785,13 +4785,8 @@ make_face_cache (struct frame *f)
   c->f = f;
   c->size = 50;
   c->used = 0;
-#ifdef HAVE_MPS
-  c->buckets = igc_make_ptr_vec (FACE_CACHE_BUCKETS_SIZE);
-  c->faces_by_id = igc_make_ptr_vec (c->size);
-#else
   c->buckets = xzalloc (FACE_CACHE_BUCKETS_SIZE * sizeof *c->buckets);
   c->faces_by_id = xzalloc (c->size * sizeof *c->faces_by_id);
-#endif
   c->menu_face_changed_p = menu_face_changed_default;
   return c;
 }
@@ -4898,13 +4893,13 @@ free_face_cache (struct face_cache *c)
   if (c)
     {
       free_realized_faces (c);
-#ifndef HAVE_MPS
       struct face **p = c->buckets;
       c->buckets = NULL;
       xfree (p);
       p = c->faces_by_id;
       c->faces_by_id = NULL;
       xfree (p);
+#ifndef HAVE_MPS
       xfree (c);
 #endif
     }
@@ -4978,13 +4973,9 @@ cache_face (struct face_cache *c, struct face *face, 
uintptr_t hash)
     {
       if (c->used == c->size)
        {
-#ifdef HAVE_MPS
-         c->faces_by_id = igc_grow_ptr_vec (c->faces_by_id, &c->size, 1, 
MAX_FACE_ID);
-#else
          c->faces_by_id
            = xpalloc (c->faces_by_id, &c->size, 1, MAX_FACE_ID,
                       sizeof *c->faces_by_id);
-#endif
        }
       c->used++;
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]