emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 0f09808: Adjust remaining uses of `NILP (HASH_HASH)


From: Stefan Monnier
Subject: [Emacs-diffs] master 0f09808: Adjust remaining uses of `NILP (HASH_HASH)`.
Date: Fri, 26 Jul 2019 16:56:17 -0400 (EDT)

branch: master
commit 0f09808e522cd3de6bd9ea1350beed1feddfbda9
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    Adjust remaining uses of `NILP (HASH_HASH)`.
    
    * src/json.c (lisp_to_json_toplevel_1):
    * src/pdumper.c (dump_hash_table_stable_p, hash_table_contents):
    * src/print.c (print, print_vectorlike):
    * src/minibuf.c (Ftry_completion, Fall_completions, Ftest_completion):
    Use `EQ (HASH_KEY, Qunbound)` instead of `NILP (HASH_HASH)`.
---
 src/json.c    | 41 ++++++++++++++++++++++-------------------
 src/minibuf.c |  6 +++---
 src/pdumper.c | 33 +++++++++++++++++++--------------
 src/print.c   | 26 ++++++++++++++++----------
 4 files changed, 60 insertions(+), 46 deletions(-)

diff --git a/src/json.c b/src/json.c
index d05f2c5..5a3d001 100644
--- a/src/json.c
+++ b/src/json.c
@@ -361,28 +361,31 @@ lisp_to_json_toplevel_1 (Lisp_Object lisp,
       count = SPECPDL_INDEX ();
       record_unwind_protect_ptr (json_release_object, json);
       for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (h); ++i)
-        if (!NILP (HASH_HASH (h, i)))
-          {
-            Lisp_Object key = json_encode (HASH_KEY (h, i));
-            /* We can't specify the length, so the string must be
+        {
+          Lisp_Object key = HASH_KEY (h, i);
+          if (!EQ (key, Qunbound))
+            {
+              Lisp_Object ekey = json_encode (key);
+              /* We can't specify the length, so the string must be
                NUL-terminated.  */
-            check_string_without_embedded_nuls (key);
-            const char *key_str = SSDATA (key);
-            /* Reject duplicate keys.  These are possible if the hash
+              check_string_without_embedded_nuls (ekey);
+              const char *key_str = SSDATA (ekey);
+              /* Reject duplicate keys.  These are possible if the hash
                table test is not `equal'.  */
-            if (json_object_get (json, key_str) != NULL)
-              wrong_type_argument (Qjson_value_p, lisp);
-            int status = json_object_set_new (json, key_str,
-                                              lisp_to_json (HASH_VALUE (h, i),
-                                                            conf));
-            if (status == -1)
-              {
-                /* A failure can be caused either by an invalid key or
+              if (json_object_get (json, key_str) != NULL)
+                wrong_type_argument (Qjson_value_p, lisp);
+              int status
+                = json_object_set_new (json, key_str,
+                                       lisp_to_json (HASH_VALUE (h, i), conf));
+              if (status == -1)
+                {
+                  /* A failure can be caused either by an invalid key or
                    by low memory.  */
-                json_check_utf8 (key);
-                json_out_of_memory ();
-              }
-          }
+                  json_check_utf8 (ekey);
+                  json_out_of_memory ();
+                }
+            }
+        }
     }
   else if (NILP (lisp))
     return json_check (json_object ());
diff --git a/src/minibuf.c b/src/minibuf.c
index 8920f37..14a0dbe 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1245,7 +1245,7 @@ is used to further constrain the set of candidates.  */)
       else /* if (type == hash_table) */
        {
          while (idx < HASH_TABLE_SIZE (XHASH_TABLE (collection))
-                && NILP (HASH_HASH (XHASH_TABLE (collection), idx)))
+                && EQ (HASH_KEY (XHASH_TABLE (collection), idx), Qunbound))
            idx++;
          if (idx >= HASH_TABLE_SIZE (XHASH_TABLE (collection)))
            break;
@@ -1497,7 +1497,7 @@ with a space are ignored unless STRING itself starts with 
a space.  */)
       else /* if (type == 3) */
        {
          while (idx < HASH_TABLE_SIZE (XHASH_TABLE (collection))
-                && NILP (HASH_HASH (XHASH_TABLE (collection), idx)))
+                && EQ (HASH_KEY (XHASH_TABLE (collection), idx), Qunbound))
            idx++;
          if (idx >= HASH_TABLE_SIZE (XHASH_TABLE (collection)))
            break;
@@ -1724,8 +1724,8 @@ the values STRING, PREDICATE and `lambda'.  */)
       else
        for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
           {
-            if (NILP (HASH_HASH (h, i))) continue;
             tem = HASH_KEY (h, i);
+            if (EQ (tem, Qunbound)) continue;
             Lisp_Object strkey = (SYMBOLP (tem) ? Fsymbol_name (tem) : tem);
             if (!STRINGP (strkey)) continue;
             if (EQ (Fcompare_strings (string, Qnil, Qnil,
diff --git a/src/pdumper.c b/src/pdumper.c
index 1a5d1f3..31f4f33 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -2629,18 +2629,20 @@ dump_hash_table_stable_p (const struct Lisp_Hash_Table 
*hash)
   bool is_equal = hash->test.hashfn == hashfn_equal;
   ptrdiff_t size = HASH_TABLE_SIZE (hash);
   for (ptrdiff_t i = 0; i < size; ++i)
-    if (!NILP (HASH_HASH (hash, i)))
-      {
-        Lisp_Object key =  HASH_KEY (hash, i);
-       bool key_stable = (dump_builtin_symbol_p (key)
-                          || FIXNUMP (key)
-                          || (is_equal
-                              && (STRINGP (key) || BOOL_VECTOR_P (key)))
-                          || ((is_equal || is_eql)
-                              && (FLOATP (key) || BIGNUMP (key))));
-        if (!key_stable)
-          return false;
-      }
+    {
+      Lisp_Object key =  HASH_KEY (hash, i);
+      if (!EQ (key, Qunbound))
+        {
+         bool key_stable = (dump_builtin_symbol_p (key)
+                            || FIXNUMP (key)
+                            || (is_equal
+                                && (STRINGP (key) || BOOL_VECTOR_P (key)))
+                            || ((is_equal || is_eql)
+                                && (FLOATP (key) || BIGNUMP (key))));
+          if (!key_stable)
+            return false;
+        }
+    }
 
   return true;
 }
@@ -2652,8 +2654,11 @@ hash_table_contents (Lisp_Object table)
   Lisp_Object contents = Qnil;
   struct Lisp_Hash_Table *h = XHASH_TABLE (table);
   for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (h); ++i)
-    if (!NILP (HASH_HASH (h, i)))
-      dump_push (&contents, Fcons (HASH_KEY (h, i), HASH_VALUE (h, i)));
+    {
+      Lisp_Object key =  HASH_KEY (h, i);
+      if (!EQ (key, Qunbound))
+        dump_push (&contents, Fcons (key, HASH_VALUE (h, i)));
+    }
   return Fnreverse (contents);
 }
 
diff --git a/src/print.c b/src/print.c
index cb34090..7c3da68 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1135,9 +1135,12 @@ print (Lisp_Object obj, Lisp_Object printcharfun, bool 
escapeflag)
          ptrdiff_t i;
 
          for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
-           if (!NILP (HASH_HASH (h, i))
-               && EQ (HASH_VALUE (h, i), Qt))
-             Fremhash (HASH_KEY (h, i), Vprint_number_table);
+            {
+              Lisp_Object key =  HASH_KEY (h, i);
+             if (!EQ (key, Qunbound)
+                 && EQ (HASH_VALUE (h, i), Qt))
+               Fremhash (key, Vprint_number_table);
+            }
        }
     }
 
@@ -1593,13 +1596,16 @@ print_vectorlike (Lisp_Object obj, Lisp_Object 
printcharfun, bool escapeflag,
 
        printchar ('(', printcharfun);
        for (ptrdiff_t i = 0; i < size; i++)
-         if (!NILP (HASH_HASH (h, i)))
-           {
-             if (i) printchar (' ', printcharfun);
-             print_object (HASH_KEY (h, i), printcharfun, escapeflag);
-             printchar (' ', printcharfun);
-             print_object (HASH_VALUE (h, i), printcharfun, escapeflag);
-           }
+          {
+            Lisp_Object key = HASH_KEY (h, i);
+           if (!EQ (key, Qunbound))
+             {
+               if (i) printchar (' ', printcharfun);
+               print_object (key, printcharfun, escapeflag);
+               printchar (' ', printcharfun);
+               print_object (HASH_VALUE (h, i), printcharfun, escapeflag);
+             }
+          }
 
        if (size < real_size)
          print_c_string (" ...", printcharfun);



reply via email to

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