emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r117528: * lisp.h (CHECK_VECTOR_OR_STRING): Return n


From: Dmitry Antipov
Subject: [Emacs-diffs] trunk r117528: * lisp.h (CHECK_VECTOR_OR_STRING): Return number of elements
Date: Mon, 14 Jul 2014 04:46:04 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117528
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Mon 2014-07-14 08:44:01 +0400
message:
  * lisp.h (CHECK_VECTOR_OR_STRING): Return number of elements
  or characters in string, respectively.  Add comment.
  * fringe.c (Fdefine_fringe_bitmap):
  * fns.c (Fsubstring, substring_both): Use it.
  * keymap.c (Fdefine_key, Flookup_key):
  * macros.c (Fstart_kbd_macro): Likewise.  Avoid call to Flength.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/fns.c                      fns.c-20091113204419-o5vbwnq5f7feedwu-203
  src/fringe.c                   fringe.c-20091113204419-o5vbwnq5f7feedwu-2965
  src/keymap.c                   keymap.c-20091113204419-o5vbwnq5f7feedwu-219
  src/lisp.h                     lisp.h-20091113204419-o5vbwnq5f7feedwu-253
  src/macros.c                   macros.c-20091113204419-o5vbwnq5f7feedwu-217
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-07-13 15:50:35 +0000
+++ b/src/ChangeLog     2014-07-14 04:44:01 +0000
@@ -1,3 +1,12 @@
+2014-07-14  Dmitry Antipov  <address@hidden>
+
+       * lisp.h (CHECK_VECTOR_OR_STRING): Return number of elements
+       or characters in string, respectively.  Add comment.
+       * fringe.c (Fdefine_fringe_bitmap):
+       * fns.c (Fsubstring, substring_both): Use it.
+       * keymap.c (Fdefine_key, Flookup_key):
+       * macros.c (Fstart_kbd_macro): Likewise.  Avoid call to Flength.
+
 2014-07-13  Paul Eggert  <address@hidden>
 
        Improve behavior of 'bzr up; cd src; make -k'.

=== modified file 'src/fns.c'
--- a/src/fns.c 2014-06-26 07:13:13 +0000
+++ b/src/fns.c 2014-07-14 04:44:01 +0000
@@ -1151,13 +1151,7 @@
   Lisp_Object res;
   ptrdiff_t size, ifrom, ito;
 
-  if (STRINGP (string))
-    size = SCHARS (string);
-  else if (VECTORP (string))
-    size = ASIZE (string);
-  else
-    wrong_type_argument (Qarrayp, string);
-
+  size = CHECK_VECTOR_OR_STRING (string);
   validate_subarray (string, from, to, size, &ifrom, &ito);
 
   if (STRINGP (string))
@@ -1212,11 +1206,7 @@
                ptrdiff_t to, ptrdiff_t to_byte)
 {
   Lisp_Object res;
-  ptrdiff_t size;
-
-  CHECK_VECTOR_OR_STRING (string);
-
-  size = STRINGP (string) ? SCHARS (string) : ASIZE (string);
+  ptrdiff_t size = CHECK_VECTOR_OR_STRING (string);
 
   if (!(0 <= from && from <= to && to <= size))
     args_out_of_range_3 (string, make_number (from), make_number (to));

=== modified file 'src/fringe.c'
--- a/src/fringe.c      2014-06-10 03:13:41 +0000
+++ b/src/fringe.c      2014-07-14 04:44:01 +0000
@@ -1571,13 +1571,7 @@
   int fill1 = 0, fill2 = 0;
 
   CHECK_SYMBOL (bitmap);
-
-  if (STRINGP (bits))
-    h = SCHARS (bits);
-  else if (VECTORP (bits))
-    h = ASIZE (bits);
-  else
-    wrong_type_argument (Qsequencep, bits);
+  h = CHECK_VECTOR_OR_STRING (bits);
 
   if (NILP (height))
     fb.height = h;

=== modified file 'src/keymap.c'
--- a/src/keymap.c      2014-07-02 01:49:31 +0000
+++ b/src/keymap.c      2014-07-14 04:44:01 +0000
@@ -1092,9 +1092,7 @@
   GCPRO3 (keymap, key, def);
   keymap = get_keymap (keymap, 1, 1);
 
-  CHECK_VECTOR_OR_STRING (key);
-
-  length = XFASTINT (Flength (key));
+  length = CHECK_VECTOR_OR_STRING (key);
   if (length == 0)
     RETURN_UNGCPRO (Qnil);
 
@@ -1248,9 +1246,7 @@
   GCPRO2 (keymap, key);
   keymap = get_keymap (keymap, 1, 1);
 
-  CHECK_VECTOR_OR_STRING (key);
-
-  length = XFASTINT (Flength (key));
+  length = CHECK_VECTOR_OR_STRING (key);
   if (length == 0)
     RETURN_UNGCPRO (keymap);
 

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2014-07-08 07:17:04 +0000
+++ b/src/lisp.h        2014-07-14 04:44:01 +0000
@@ -2555,10 +2555,15 @@
 {
   CHECK_TYPE (BOOL_VECTOR_P (x), Qbool_vector_p, x);
 }
-INLINE void
+/* This is a bit special because we always need size afterwards.  */
+INLINE ptrdiff_t
 CHECK_VECTOR_OR_STRING (Lisp_Object x)
 {
-  CHECK_TYPE (VECTORP (x) || STRINGP (x), Qarrayp, x);
+  if (VECTORP (x))
+    return ASIZE (x);
+  if (STRINGP (x))
+    return SCHARS (x);
+  wrong_type_argument (Qarrayp, x);
 }
 INLINE void
 CHECK_ARRAY (Lisp_Object x, Lisp_Object predicate)

=== modified file 'src/macros.c'
--- a/src/macros.c      2014-06-17 16:09:19 +0000
+++ b/src/macros.c      2014-07-14 04:44:01 +0000
@@ -80,28 +80,24 @@
     }
   else
     {
-      ptrdiff_t i;
-      EMACS_INT len;
+      const ptrdiff_t incr = 30;
+      ptrdiff_t i, len;
       bool cvt;
 
       /* Check the type of last-kbd-macro in case Lisp code changed it.  */
-      CHECK_VECTOR_OR_STRING (KVAR (current_kboard, Vlast_kbd_macro));
+      len = CHECK_VECTOR_OR_STRING (KVAR (current_kboard, Vlast_kbd_macro));
 
-      len = XINT (Flength (KVAR (current_kboard, Vlast_kbd_macro)));
+      if (INT_ADD_OVERFLOW (len, incr))
+       memory_full (SIZE_MAX);
 
       /* Copy last-kbd-macro into the buffer, in case the Lisp code
         has put another macro there.  */
-      if (current_kboard->kbd_macro_bufsize < len + 30)
-       {
-         if (PTRDIFF_MAX < MOST_POSITIVE_FIXNUM + 30
-             && PTRDIFF_MAX < len + 30)
-           memory_full (SIZE_MAX);
-         current_kboard->kbd_macro_buffer =
-           xpalloc (current_kboard->kbd_macro_buffer,
-                    &current_kboard->kbd_macro_bufsize,
-                    len + 30 - current_kboard->kbd_macro_bufsize, -1,
-                    sizeof *current_kboard->kbd_macro_buffer);
-       }
+      if (current_kboard->kbd_macro_bufsize < len + incr)
+       current_kboard->kbd_macro_buffer =
+         xpalloc (current_kboard->kbd_macro_buffer,
+                  &current_kboard->kbd_macro_bufsize,
+                  len + incr - current_kboard->kbd_macro_bufsize, -1,
+                  sizeof *current_kboard->kbd_macro_buffer);
 
       /* Must convert meta modifier when copying string to vector.  */
       cvt = STRINGP (KVAR (current_kboard, Vlast_kbd_macro));


reply via email to

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