From: Mattias EngdegÄrd Date: Thu, 26 Oct 2023 16:36:05 +0000 (+0200) Subject: Don't print or read the hash table size parameter X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3f9c81a87f7bce854489b8232d817b536ccf349b;p=emacs.git Don't print or read the hash table size parameter It's not a meaningful part of the external representation. This allows for faster printing and reading, smaller external representation, and less memory consumption. * src/print.c (print_object): Omit size. * src/lread.c (hash_table_from_plist): Take size from the data. --- diff --git a/src/lread.c b/src/lread.c index e95dafcf222..18894801376 100644 --- a/src/lread.c +++ b/src/lread.c @@ -3426,7 +3426,6 @@ hash_table_from_plist (Lisp_Object plist) } \ } while (0) - ADDPARAM (size); ADDPARAM (test); ADDPARAM (weakness); ADDPARAM (rehash_size); @@ -3434,23 +3433,25 @@ hash_table_from_plist (Lisp_Object plist) ADDPARAM (purecopy); Lisp_Object data = plist_get (plist, Qdata); + if (!(NILP (data) || CONSP (data))) + error ("Hash table data is not a list"); + ptrdiff_t data_len = list_length (data); + if (data_len & 1) + error ("Hash table data length is odd"); + *par++ = QCsize; + *par++ = make_fixnum (data_len / 2); /* Now use params to make a new hash table and fill it. */ Lisp_Object ht = Fmake_hash_table (par - params, params); - Lisp_Object last = data; - FOR_EACH_TAIL_SAFE (data) + while (!NILP (data)) { Lisp_Object key = XCAR (data); data = XCDR (data); - if (!CONSP (data)) - break; Lisp_Object val = XCAR (data); - last = XCDR (data); Fputhash (key, val, ht); + data = XCDR (data); } - if (!NILP (last)) - error ("Hash table data is not a list of even length"); return ht; } diff --git a/src/print.c b/src/print.c index d011962d85b..c1c91b2383a 100644 --- a/src/print.c +++ b/src/print.c @@ -2574,11 +2574,8 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) { struct Lisp_Hash_Table *h = XHASH_TABLE (obj); /* Implement a readable output, e.g.: - #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */ - /* Always print the size. */ - int len = sprintf (buf, "#s(hash-table size %"pD"d", - HASH_TABLE_SIZE (h)); - strout (buf, len, len, printcharfun); + #s(hash-table test equal data (k1 v1 k2 v2)) */ + print_c_string ("#s(hash-table", printcharfun); if (!BASE_EQ (h->test.name, Qeql)) {