[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master fe927ec: Change type of `rehash_threshold' and `pur
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] master fe927ec: Change type of `rehash_threshold' and `pure' fields in hash-tables |
Date: |
Sat, 18 Feb 2017 22:37:16 -0500 (EST) |
branch: master
commit fe927ecfe45f66ec58d9e7cab6f2526fc87a6803
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>
Change type of `rehash_threshold' and `pure' fields in hash-tables
* src/lisp.h (struct Lisp_Hash_Table): Change type of
`rehash_threshold' and `pure' fields and move them after `count'.
* src/fns.c (make_hash_table): Change type of `rehash_threshold' and `pure'.
(Fmake_hash_table, Fhash_table_rehash_threshold):
* src/category.c (hash_get_category_set):
* src/xterm.c (syms_of_xterm):
* src/profiler.c (make_log):
* src/print.c (print_object):
* src/alloc.c (purecopy_hash_table, purecopy): Adjust accordingly.
---
src/alloc.c | 8 ++++----
src/category.c | 4 ++--
src/fns.c | 30 +++++++++++++++---------------
src/lisp.h | 22 ++++++++++++----------
src/print.c | 12 +++++-------
src/profiler.c | 4 ++--
src/xterm.c | 4 ++--
7 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/src/alloc.c b/src/alloc.c
index deb1ca3..b579e7e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -5443,7 +5443,7 @@ static struct Lisp_Hash_Table *
purecopy_hash_table (struct Lisp_Hash_Table *table)
{
eassert (NILP (table->weak));
- eassert (!NILP (table->pure));
+ eassert (table->pure);
struct Lisp_Hash_Table *pure = pure_alloc (sizeof *pure, Lisp_Vectorlike);
struct hash_table_test pure_test = table->test;
@@ -5457,14 +5457,14 @@ purecopy_hash_table (struct Lisp_Hash_Table *table)
pure->header = table->header;
pure->weak = purecopy (Qnil);
pure->rehash_size = purecopy (table->rehash_size);
- pure->rehash_threshold = purecopy (table->rehash_threshold);
pure->hash = purecopy (table->hash);
pure->next = purecopy (table->next);
pure->next_free = purecopy (table->next_free);
pure->index = purecopy (table->index);
pure->count = table->count;
+ pure->pure = table->pure;
+ pure->rehash_threshold = table->rehash_threshold;
pure->key_and_value = purecopy (table->key_and_value);
- pure->pure = purecopy (table->pure);
return pure;
}
@@ -5524,7 +5524,7 @@ purecopy (Lisp_Object obj)
/* Do not purify hash tables which haven't been defined with
:purecopy as non-nil or are weak - they aren't guaranteed to
not change. */
- if (!NILP (table->weak) || NILP (table->pure))
+ if (!NILP (table->weak) || !table->pure)
{
/* Instead, add the hash table to the list of pinned objects,
so that it will be marked during GC. */
diff --git a/src/category.c b/src/category.c
index ff287a4..f5edd20 100644
--- a/src/category.c
+++ b/src/category.c
@@ -66,8 +66,8 @@ hash_get_category_set (Lisp_Object table, Lisp_Object
category_set)
(table, 1,
make_hash_table (hashtest_equal, make_number (DEFAULT_HASH_SIZE),
make_float (DEFAULT_REHASH_SIZE),
- make_float (DEFAULT_REHASH_THRESHOLD),
- Qnil, Qnil));
+ DEFAULT_REHASH_THRESHOLD,
+ Qnil, false));
h = XHASH_TABLE (XCHAR_TABLE (table)->extras[1]);
i = hash_lookup (h, category_set, &hash);
if (i >= 0)
diff --git a/src/fns.c b/src/fns.c
index ffe3218..e3e040b 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3676,8 +3676,8 @@ allocate_hash_table (void)
Lisp_Object
make_hash_table (struct hash_table_test test,
Lisp_Object size, Lisp_Object rehash_size,
- Lisp_Object rehash_threshold, Lisp_Object weak,
- Lisp_Object pure)
+ float rehash_threshold, Lisp_Object weak,
+ bool pure)
{
struct Lisp_Hash_Table *h;
Lisp_Object table;
@@ -3690,15 +3690,13 @@ make_hash_table (struct hash_table_test test,
eassert (INTEGERP (size) && XINT (size) >= 0);
eassert ((INTEGERP (rehash_size) && XINT (rehash_size) > 0)
|| (FLOATP (rehash_size) && 1 < XFLOAT_DATA (rehash_size)));
- eassert (FLOATP (rehash_threshold)
- && 0 < XFLOAT_DATA (rehash_threshold)
- && XFLOAT_DATA (rehash_threshold) <= 1.0);
+ eassert (0 < rehash_threshold && rehash_threshold <= 1.0);
if (XFASTINT (size) == 0)
size = make_number (1);
sz = XFASTINT (size);
- index_float = sz / XFLOAT_DATA (rehash_threshold);
+ index_float = sz / rehash_threshold;
index_size = (index_float < INDEX_SIZE_BOUND + 1
? next_almost_prime (index_float)
: INDEX_SIZE_BOUND + 1);
@@ -3797,7 +3795,7 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h)
else
new_size = INDEX_SIZE_BOUND + 1;
}
- index_float = new_size / XFLOAT_DATA (h->rehash_threshold);
+ index_float = new_size / h->rehash_threshold;
index_size = (index_float < INDEX_SIZE_BOUND + 1
? next_almost_prime (index_float)
: INDEX_SIZE_BOUND + 1);
@@ -4391,7 +4389,9 @@ in an error.
usage: (make-hash-table &rest KEYWORD-ARGS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
- Lisp_Object test, size, rehash_size, rehash_threshold, weak, pure;
+ Lisp_Object test, size, rehash_size, weak;
+ float rehash_threshold;
+ bool pure;
struct hash_table_test testdesc;
ptrdiff_t i;
USE_SAFE_ALLOCA;
@@ -4427,7 +4427,7 @@ usage: (make-hash-table &rest KEYWORD-ARGS) */)
/* See if there's a `:purecopy PURECOPY' argument. */
i = get_key_arg (QCpurecopy, nargs, args, used);
- pure = i ? args[i] : Qnil;
+ pure = i && !NILP (args[i]);
/* See if there's a `:size SIZE' argument. */
i = get_key_arg (QCsize, nargs, args, used);
size = i ? args[i] : Qnil;
@@ -4445,11 +4445,11 @@ usage: (make-hash-table &rest KEYWORD-ARGS) */)
/* Look for `:rehash-threshold THRESHOLD'. */
i = get_key_arg (QCrehash_threshold, nargs, args, used);
- rehash_threshold = i ? args[i] : make_float (DEFAULT_REHASH_THRESHOLD);
- if (! (FLOATP (rehash_threshold)
- && 0 < XFLOAT_DATA (rehash_threshold)
- && XFLOAT_DATA (rehash_threshold) <= 1))
- signal_error ("Invalid hash table rehash threshold", rehash_threshold);
+ rehash_threshold =
+ i ? (FLOATP (args[i]) ? XFLOAT_DATA (args[i]) : -1.0)
+ : DEFAULT_REHASH_THRESHOLD;
+ if (! (0 < rehash_threshold && rehash_threshold <= 1))
+ signal_error ("Invalid hash table rehash threshold", args[i]);
/* Look for `:weakness WEAK'. */
i = get_key_arg (QCweakness, nargs, args, used);
@@ -4504,7 +4504,7 @@ DEFUN ("hash-table-rehash-threshold",
Fhash_table_rehash_threshold,
doc: /* Return the current rehash threshold of TABLE. */)
(Lisp_Object table)
{
- return check_hash_table (table)->rehash_threshold;
+ return make_float (check_hash_table (table)->rehash_threshold);
}
diff --git a/src/lisp.h b/src/lisp.h
index 080bcf7..985d54a 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1974,10 +1974,6 @@ struct Lisp_Hash_Table
new size by multiplying the old size with this factor. */
Lisp_Object rehash_size;
- /* Resize hash table when number of entries/ table size is >= this
- ratio, a float. */
- Lisp_Object rehash_threshold;
-
/* Vector of hash codes. If hash[I] is nil, this means that the
I-th entry is unused. */
Lisp_Object hash;
@@ -1995,10 +1991,6 @@ struct Lisp_Hash_Table
hash table size to reduce collisions. */
Lisp_Object index;
- /* Non-nil if the table can be purecopied. The table cannot be
- changed afterwards. */
- Lisp_Object pure;
-
/* Only the fields above are traced normally by the GC. The ones below
`count' are special and are either ignored by the GC or traced in
a special way (e.g. because of weakness). */
@@ -2006,6 +1998,14 @@ struct Lisp_Hash_Table
/* Number of key/value entries in the table. */
ptrdiff_t count;
+ /* Non-nil if the table can be purecopied. The table cannot be
+ changed afterwards. */
+ bool_bf pure : 1;
+
+ /* Resize hash table when number of entries/ table size is >= this
+ ratio, a float. */
+ float rehash_threshold;
+
/* Vector of keys and values. The key of item I is found at index
2 * I, the value is found at index 2 * I + 1.
This is gc_marked specially if the table is weak. */
@@ -3361,8 +3361,10 @@ extern Lisp_Object larger_vector (Lisp_Object,
ptrdiff_t, ptrdiff_t);
extern void sweep_weak_hash_tables (void);
EMACS_UINT hash_string (char const *, ptrdiff_t);
EMACS_UINT sxhash (Lisp_Object, int);
-Lisp_Object make_hash_table (struct hash_table_test, Lisp_Object, Lisp_Object,
- Lisp_Object, Lisp_Object, Lisp_Object);
+Lisp_Object make_hash_table (struct hash_table_test test,
+ Lisp_Object size, Lisp_Object rehash_size,
+ float rehash_threshold, Lisp_Object weak,
+ bool pure);
ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
EMACS_UINT);
diff --git a/src/print.c b/src/print.c
index db3d00f..3a36a4e 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1812,16 +1812,14 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
print_object (h->rehash_size, printcharfun, escapeflag);
}
- if (!NILP (h->rehash_threshold))
- {
- print_c_string (" rehash-threshold ", printcharfun);
- print_object (h->rehash_threshold, printcharfun, escapeflag);
- }
+ print_c_string (" rehash-threshold ", printcharfun);
+ print_object (make_float (h->rehash_threshold),
+ printcharfun, escapeflag);
- if (!NILP (h->pure))
+ if (h->pure)
{
print_c_string (" purecopy ", printcharfun);
- print_object (h->pure, printcharfun, escapeflag);
+ print_object (h->pure ? Qt : Qnil, printcharfun, escapeflag);
}
print_c_string (" data ", printcharfun);
diff --git a/src/profiler.c b/src/profiler.c
index a223a7e..edc28fc8 100644
--- a/src/profiler.c
+++ b/src/profiler.c
@@ -47,8 +47,8 @@ make_log (EMACS_INT heap_size, EMACS_INT max_stack_depth)
Lisp_Object log = make_hash_table (hashtest_profiler,
make_number (heap_size),
make_float (DEFAULT_REHASH_SIZE),
- make_float (DEFAULT_REHASH_THRESHOLD),
- Qnil, Qnil);
+ DEFAULT_REHASH_THRESHOLD,
+ Qnil, false);
struct Lisp_Hash_Table *h = XHASH_TABLE (log);
/* What is special about our hash-tables is that the keys are pre-filled
diff --git a/src/xterm.c b/src/xterm.c
index 38229a5..b04c699 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -12876,8 +12876,8 @@ keysyms. The default is nil, which is the same as
`super'. */);
doc: /* Hash table of character codes indexed by X keysym codes. */);
Vx_keysym_table = make_hash_table (hashtest_eql, make_number (900),
make_float (DEFAULT_REHASH_SIZE),
- make_float (DEFAULT_REHASH_THRESHOLD),
- Qnil, Qnil);
+ DEFAULT_REHASH_THRESHOLD,
+ Qnil, false);
DEFVAR_BOOL ("x-frame-normalize-before-maximize",
x_frame_normalize_before_maximize,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master fe927ec: Change type of `rehash_threshold' and `pure' fields in hash-tables,
Stefan Monnier <=