]> git.eshelyaron.com Git - emacs.git/commitdiff
Prefer Fvector to make_uninit_vector
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 15 Aug 2020 17:48:36 +0000 (10:48 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 15 Aug 2020 18:19:51 +0000 (11:19 -0700)
Fvector is less error-prone than make_uninit_vector, as it
avoids the possibility of a GC crash due to an uninitialized
vector.  So prefer Fvector to make_uninit_vector when this is
easy (and when there's no significant performance difference).
Inspired by a suggestion by Pip Cet in:
https://lists.gnu.org/r/emacs-devel/2020-08/msg00313.html
* src/ccl.c (Fregister_ccl_program):
* src/ccl.c (Fregister_ccl_program):
* src/charset.c (Fdefine_charset_internal):
* src/font.c (Fquery_font, Ffont_info, syms_of_font):
* src/fontset.c (font_def_new, Fset_fontset_font):
* src/ftfont.c (ftfont_shape_by_flt):
* src/hbfont.c (hbfont_shape):
* src/macfont.m (macfont_shape):
* src/search.c (Fnewline_cache_check):
* src/xfaces.c (Fx_family_fonts):
* src/xfns.c (Fx_window_property_attributes):
Prefer Fvector to make_uninit_vector when either is easy.
* src/fontset.c (font_def_new): Now a function with one less
arg instead of a do-while macro, and renamed from FONT_DEF_NEW.
All uses changed.

src/ccl.c
src/charset.c
src/font.c
src/fontset.c
src/ftfont.c
src/hbfont.c
src/macfont.m
src/search.c
src/xfaces.c
src/xfns.c

index ef059ffff25677f2a873e412549616b06933242b..e85cfa6cdf289abcb2e12cf2d59848f2c214e4c4 100644 (file)
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -2219,15 +2219,8 @@ Return index number of the registered CCL program.  */)
     /* Extend the table.  */
     Vccl_program_table = larger_vector (Vccl_program_table, 1, -1);
 
-  {
-    Lisp_Object elt = make_uninit_vector (4);
-
-    ASET (elt, 0, name);
-    ASET (elt, 1, ccl_prog);
-    ASET (elt, 2, resolved);
-    ASET (elt, 3, Qt);
-    ASET (Vccl_program_table, idx, elt);
-  }
+  ASET (Vccl_program_table, idx,
+       CALLN (Fvector, name, ccl_prog, resolved, Qt));
 
   Fput (name, Qccl_program_idx, make_fixnum (idx));
   return make_fixnum (idx);
index 8635aad3ed6098e97d9b27f6432e11d47fa7b5c8..520dd3a9605c54a5105624625eb4300a5ba59cbe 100644 (file)
@@ -1035,12 +1035,9 @@ usage: (define-charset-internal ...)  */)
       CHECK_FIXNAT (parent_max_code);
       parent_code_offset = Fnth (make_fixnum (3), val);
       CHECK_FIXNUM (parent_code_offset);
-      val = make_uninit_vector (4);
-      ASET (val, 0, make_fixnum (parent_charset->id));
-      ASET (val, 1, parent_min_code);
-      ASET (val, 2, parent_max_code);
-      ASET (val, 3, parent_code_offset);
-      ASET (attrs, charset_subset, val);
+      ASET (attrs, charset_subset,
+           CALLN (Fvector, make_fixnum (parent_charset->id),
+                  parent_min_code, parent_max_code, parent_code_offset));
 
       charset.method = CHARSET_METHOD_SUBSET;
       /* Here, we just copy the parent's fast_map.  It's not accurate,
index ccbd3fc9ce65fb29885e5167df93a58fda7acec1..5c01c7ff79664890bb598e4adfad37e5ad9942f6 100644 (file)
@@ -4847,21 +4847,18 @@ If the font is not OpenType font, CAPABILITY is nil.  */)
   (Lisp_Object font_object)
 {
   struct font *font = CHECK_FONT_GET_OBJECT (font_object);
-  Lisp_Object val = make_uninit_vector (9);
-
-  ASET (val, 0, AREF (font_object, FONT_NAME_INDEX));
-  ASET (val, 1, AREF (font_object, FONT_FILE_INDEX));
-  ASET (val, 2, make_fixnum (font->pixel_size));
-  ASET (val, 3, make_fixnum (font->max_width));
-  ASET (val, 4, make_fixnum (font->ascent));
-  ASET (val, 5, make_fixnum (font->descent));
-  ASET (val, 6, make_fixnum (font->space_width));
-  ASET (val, 7, make_fixnum (font->average_width));
-  if (font->driver->otf_capability)
-    ASET (val, 8, Fcons (Qopentype, font->driver->otf_capability (font)));
-  else
-    ASET (val, 8, Qnil);
-  return val;
+  return CALLN (Fvector,
+               AREF (font_object, FONT_NAME_INDEX),
+               AREF (font_object, FONT_FILE_INDEX),
+               make_fixnum (font->pixel_size),
+               make_fixnum (font->max_width),
+               make_fixnum (font->ascent),
+               make_fixnum (font->descent),
+               make_fixnum (font->space_width),
+               make_fixnum (font->average_width),
+               (font->driver->otf_capability
+                ? Fcons (Qopentype, font->driver->otf_capability (font))
+                : Qnil));
 }
 
 DEFUN ("font-get-glyphs", Ffont_get_glyphs, Sfont_get_glyphs, 3, 4, 0,
@@ -5168,24 +5165,23 @@ If the named font cannot be opened and loaded, return nil.  */)
     return Qnil;
   font = XFONT_OBJECT (font_object);
 
-  info = make_uninit_vector (14);
-  ASET (info, 0, AREF (font_object, FONT_NAME_INDEX));
-  ASET (info, 1, AREF (font_object, FONT_FULLNAME_INDEX));
-  ASET (info, 2, make_fixnum (font->pixel_size));
-  ASET (info, 3, make_fixnum (font->height));
-  ASET (info, 4, make_fixnum (font->baseline_offset));
-  ASET (info, 5, make_fixnum (font->relative_compose));
-  ASET (info, 6, make_fixnum (font->default_ascent));
-  ASET (info, 7, make_fixnum (font->max_width));
-  ASET (info, 8, make_fixnum (font->ascent));
-  ASET (info, 9, make_fixnum (font->descent));
-  ASET (info, 10, make_fixnum (font->space_width));
-  ASET (info, 11, make_fixnum (font->average_width));
-  ASET (info, 12, AREF (font_object, FONT_FILE_INDEX));
-  if (font->driver->otf_capability)
-    ASET (info, 13, Fcons (Qopentype, font->driver->otf_capability (font)));
-  else
-    ASET (info, 13, Qnil);
+  info = CALLN (Fvector,
+               AREF (font_object, FONT_NAME_INDEX),
+               AREF (font_object, FONT_FULLNAME_INDEX),
+               make_fixnum (font->pixel_size),
+               make_fixnum (font->height),
+               make_fixnum (font->baseline_offset),
+               make_fixnum (font->relative_compose),
+               make_fixnum (font->default_ascent),
+               make_fixnum (font->max_width),
+               make_fixnum (font->ascent),
+               make_fixnum (font->descent),
+               make_fixnum (font->space_width),
+               make_fixnum (font->average_width),
+               AREF (font_object, FONT_FILE_INDEX),
+               (font->driver->otf_capability
+                ? Fcons (Qopentype, font->driver->otf_capability (font))
+                : Qnil));
 
 #if 0
   /* As font_object is still in FONT_OBJLIST of the entity, we can't
@@ -5494,10 +5490,8 @@ This variable cannot be set; trying to do so will signal an error.  */);
   make_symbol_constant (intern_c_string ("font-width-table"));
 
   staticpro (&font_style_table);
-  font_style_table = make_uninit_vector (3);
-  ASET (font_style_table, 0, Vfont_weight_table);
-  ASET (font_style_table, 1, Vfont_slant_table);
-  ASET (font_style_table, 2, Vfont_width_table);
+  font_style_table = CALLN (Fvector, Vfont_weight_table, Vfont_slant_table,
+                           Vfont_width_table);
 
   DEFVAR_LISP ("font-log", Vfont_log, doc: /*
 A list that logs font-related actions and results, for debugging.
index c2bb8b21f26120a5d469a6f2b26c2d4afdec6b60..8c86075c07ebd7d82f70af83e900df0a9c49af85 100644 (file)
@@ -252,14 +252,13 @@ set_fontset_fallback (Lisp_Object fontset, Lisp_Object fallback)
 
 #define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
 
-/* Macros for FONT-DEF and RFONT-DEF of fontset.  */
-#define FONT_DEF_NEW(font_def, font_spec, encoding, repertory) \
-  do {                                                         \
-    (font_def) = make_uninit_vector (3);                       \
-    ASET ((font_def), 0, font_spec);                           \
-    ASET ((font_def), 1, encoding);                            \
-    ASET ((font_def), 2, repertory);                           \
-  } while (0)
+/* Definitions for FONT-DEF and RFONT-DEF of fontset.  */
+static Lisp_Object
+font_def_new (Lisp_Object font_spec, Lisp_Object encoding,
+             Lisp_Object repertory)
+{
+  return CALLN (Fvector, font_spec, encoding, repertory);
+}
 
 #define FONT_DEF_SPEC(font_def) AREF (font_def, 0)
 #define FONT_DEF_ENCODING(font_def) AREF (font_def, 1)
@@ -1547,7 +1546,7 @@ appended.  By default, FONT-SPEC overrides the previous settings.  */)
              repertory = CHARSET_SYMBOL_ID (repertory);
            }
        }
-      FONT_DEF_NEW (font_def, font_spec, encoding, repertory);
+      font_def = font_def_new (font_spec, encoding, repertory);
     }
   else
     font_def = Qnil;
@@ -1619,14 +1618,8 @@ appended.  By default, FONT-SPEC overrides the previous settings.  */)
 
   if (charset)
     {
-      Lisp_Object arg;
-
-      arg = make_uninit_vector (5);
-      ASET (arg, 0, fontset);
-      ASET (arg, 1, font_def);
-      ASET (arg, 2, add);
-      ASET (arg, 3, ascii_changed ? Qt : Qnil);
-      ASET (arg, 4, range_list);
+      Lisp_Object arg = CALLN (Fvector, fontset, font_def, add,
+                              ascii_changed ? Qt : Qnil, range_list);
 
       map_charset_chars (set_fontset_font, Qnil, arg, charset,
                         CHARSET_MIN_CODE (charset),
index 696f5e6534154b292fb7c308107a7d0b691247f4..a904007a3299ab9c93fba0a7c8ecf30dab06f937 100644 (file)
@@ -2826,14 +2826,10 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font,
       LGLYPH_SET_ASCENT (lglyph, g->g.ascent >> 6);
       LGLYPH_SET_DESCENT (lglyph, g->g.descent >> 6);
       if (g->g.adjusted)
-       {
-         Lisp_Object vec = make_uninit_vector (3);
-
-         ASET (vec, 0, make_fixnum (g->g.xoff >> 6));
-         ASET (vec, 1, make_fixnum (g->g.yoff >> 6));
-         ASET (vec, 2, make_fixnum (g->g.xadv >> 6));
-         LGLYPH_SET_ADJUSTMENT (lglyph, vec);
-       }
+       LGLYPH_SET_ADJUSTMENT (lglyph, CALLN (Fvector,
+                                             make_fixnum (g->g.xoff >> 6),
+                                             make_fixnum (g->g.yoff >> 6),
+                                             make_fixnum (g->g.xadv >> 6)));
     }
   return make_fixnum (i);
 }
index 4b3f64ef504a604bbe03c21a6435cee7697c3f02..82b115e68683cf70203d97dff2b79e05a46cdddb 100644 (file)
@@ -594,13 +594,10 @@ hbfont_shape (Lisp_Object lgstring, Lisp_Object direction)
       yoff = - lround (pos[i].y_offset * position_unit);
       wadjust = lround (pos[i].x_advance * position_unit);
       if (xoff || yoff || wadjust != metrics.width)
-       {
-         Lisp_Object vec = make_uninit_vector (3);
-         ASET (vec, 0, make_fixnum (xoff));
-         ASET (vec, 1, make_fixnum (yoff));
-         ASET (vec, 2, make_fixnum (wadjust));
-         LGLYPH_SET_ADJUSTMENT (lglyph, vec);
-       }
+       LGLYPH_SET_ADJUSTMENT (lglyph, CALLN (Fvector,
+                                             make_fixnum (xoff),
+                                             make_fixnum (yoff),
+                                             make_fixnum (wadjust)));
     }
 
   return make_fixnum (glyph_len);
index c7430d327723c2386909057fb0d0732267b1177d..904814647f90bc4818f457c4c056a3dc016d2dd3 100644 (file)
@@ -3137,10 +3137,8 @@ macfont_shape (Lisp_Object lgstring, Lisp_Object direction)
        wadjust = lround (gl->advance);
       if (xoff != 0 || yoff != 0 || wadjust != metrics.width)
         {
-          Lisp_Object vec = make_uninit_vector (3);
-          ASET (vec, 0, make_fixnum (xoff));
-          ASET (vec, 1, make_fixnum (yoff));
-          ASET (vec, 2, make_fixnum (wadjust));
+          Lisp_Object vec = CALLN (Fvector, make_fixnum (xoff),
+                                  make_fixnum (yoff), make_fixnum (wadjust));
           LGLYPH_SET_ADJUSTMENT (lglyph, vec);
         }
     }
index 23b31d9281026f595454764dd08148fbdddfa552..6fb3716cd43bfff90c20fe46f4a9618936716ece 100644 (file)
@@ -3306,9 +3306,7 @@ the buffer.  If the buffer doesn't have a cache, the value is nil.  */)
     }
 
   /* Construct the value and return it.  */
-  val = make_uninit_vector (2);
-  ASET (val, 0, cache_newlines);
-  ASET (val, 1, buf_newlines);
+  val = CALLN (Fvector, cache_newlines, buf_newlines);
 
   if (old != NULL)
     set_buffer_internal_1 (old);
index 2c6e593f6311ad9faa40fabc3a3ab113aa573562..06d2f994de622bc2100fd4b3b6f3c3225ad2e4ea 100644 (file)
@@ -1572,22 +1572,18 @@ the face font sort order.  */)
   for (i = nfonts - 1; i >= 0; --i)
     {
       Lisp_Object font = AREF (vec, i);
-      Lisp_Object v = make_uninit_vector (8);
-      int point;
-      Lisp_Object spacing;
-
-      ASET (v, 0, AREF (font, FONT_FAMILY_INDEX));
-      ASET (v, 1, FONT_WIDTH_SYMBOLIC (font));
-      point = PIXEL_TO_POINT (XFIXNUM (AREF (font, FONT_SIZE_INDEX)) * 10,
-                             FRAME_RES_Y (f));
-      ASET (v, 2, make_fixnum (point));
-      ASET (v, 3, FONT_WEIGHT_SYMBOLIC (font));
-      ASET (v, 4, FONT_SLANT_SYMBOLIC (font));
-      spacing = Ffont_get (font, QCspacing);
-      ASET (v, 5, (NILP (spacing) || EQ (spacing, Qp)) ? Qnil : Qt);
-      ASET (v, 6, Ffont_xlfd_name (font, Qnil));
-      ASET (v, 7, AREF (font, FONT_REGISTRY_INDEX));
-
+      int point = PIXEL_TO_POINT (XFIXNUM (AREF (font, FONT_SIZE_INDEX)) * 10,
+                                 FRAME_RES_Y (f));
+      Lisp_Object spacing = Ffont_get (font, QCspacing);
+      Lisp_Object v = CALLN (Fvector,
+                            AREF (font, FONT_FAMILY_INDEX),
+                            FONT_WIDTH_SYMBOLIC (font),
+                            make_fixnum (point),
+                            FONT_WEIGHT_SYMBOLIC (font),
+                            FONT_SLANT_SYMBOLIC (font),
+                            NILP (spacing) || EQ (spacing, Qp) ? Qnil : Qt,
+                            Ffont_xlfd_name (font, Qnil),
+                            AREF (font, FONT_REGISTRY_INDEX));
       result = Fcons (v, result);
     }
 
index 09dcbbfb92de3e7afb9220f47df6bb32cc297df8..07bba90eaf209a31939e38a9e46e9f75b23c4e14 100644 (file)
@@ -6196,10 +6196,10 @@ Otherwise, the return value is a vector with the following fields:
     {
       XFree (tmp_data);
 
-      prop_attr = make_uninit_vector (3);
-      ASET (prop_attr, 0, make_fixnum (actual_type));
-      ASET (prop_attr, 1, make_fixnum (actual_format));
-      ASET (prop_attr, 2, make_fixnum (bytes_remaining / (actual_format >> 3)));
+      prop_attr = CALLN (Fvector,
+                        make_fixnum (actual_type),
+                        make_fixnum (actual_format),
+                        make_fixnum (bytes_remaining / (actual_format >> 3)));
     }
 
   unblock_input ();