1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-28 08:11:05 -08:00
Commit graph

170504 commits

Author SHA1 Message Date
Mattias Engdegård
a83e60eccb Fix recent ses-tests mistakes (bug#5852)
* test/lisp/ses-tests.el
(ses-set-formula-write-cells-with-changed-references):
Quote constant list.  Remove unused variable.
2024-01-14 14:17:41 +01:00
Mattias Engdegård
d4b1e2c3b6 Use forward-line instead of next-line in noninteractive test
* test/lisp/textmodes/page-tests.el (page-tests-what-page):
Silence byte-compiler warning; forward-line works nicely here.
2024-01-14 14:17:41 +01:00
Mattias Engdegård
cd0855cbd8 Make object-intervals linear instead of quadratic
* src/fns.c (collect_interval, Fobject_intervals):
Build the returned list in reverse instead of appending single
elements.
2024-01-14 14:17:41 +01:00
Mattias Engdegård
3869944bb4 Speed up sxhash-equal-including-properties
This function now no longer conses at all.  Previously, it constructed
a list structure of all string intervals for the sole purpose of
hashing.

* src/fns.c (hash_interval): New.
(Fsxhash_equal_including_properties):
Use it instead of collect_interval.
2024-01-14 14:17:41 +01:00
Mattias Engdegård
a9cee9c667 Retype traverse_interval arg type from Lisp_Object to void *
This is a refactoring.  It eliminates a few unnecessary conses and
allows for further improvements.

* src/intervals.c (traverse_intervals):
Change argument type.  All callers adapted.
* src/fns.c (collect_interval, Fsxhash_equal_including_properties)
(Fobject_intervals):
* src/print.c (print_check_string_charset_prop)
(print_prune_string_charset, print_object, print_interval):
Pass a pointer to a Lisp_Object instead of a Lisp_Object.
2024-01-14 14:17:40 +01:00
Po Lu
dd83db2e23 Correct implementations of FLIPRGON and FLIPRGOFF
* src/sfnt.c (sfnt_interpret_fliprgoff)
(sfnt_interpret_fliprgon): Reorder arguments to match
the order in which arguments are popped by macro wrappers.
Fix sundry typos.
2024-01-14 21:07:21 +08:00
Po Lu
c566ee9d06 Fix bug#65116
* src/xterm.c (xi_focus_handle_for_device): Correct typo.
(x_focus_frame): Don't focus frames Emacs believes to be
focused if they are frames with independent minibuffer
frames.  (bug#65116)
2024-01-14 08:28:20 +08:00
Mattias Engdegård
d2c3a98314 Hash-table documentation updates (bug#68244)
* doc/lispref/hash.texi (Creating Hash, Other Hash):
Manual updates for make-hash-table, hash-table-rehash-size and
hash-table-rehash-threshold.
* doc/lispref/objects.texi (Hash Table Type): Update example.
* src/fns.c (Fhash_table_rehash_size, Fhash_table_rehash_threshold):
Update doc strings.
* etc/NEWS: Announce changes.
2024-01-13 20:52:08 +01:00
Mattias Engdegård
519c7ca735 Don't pretend that hash-table-size is useful
* lisp/emacs-lisp/shortdoc.el (hash-table): Remove hash-table-size entry.
* doc/lispref/hash.texi (Other Hash):
* src/fns.c (Fhash_table_size): Make it clear that hash-table-size is
probably not worth using.
2024-01-13 20:50:39 +01:00
Mattias Engdegård
1998039f7a Change hash_hash_t to uint32_t
This saves a lot of memory and is quite sufficient.  Hash functions
are adapted to produce a hash_hash_t eventually, which eliminates some
useless and information-destroying intermediate hash reduction steps.

We still use EMACS_UINT for most of the actual hashing steps before
producing the final value; this may be slightly wasteful on 32-bit
platforms with 64-bit EMACS_UINT.

* src/lisp.h (hash_hash_t): Change to uint32_t.
* src/fns.c (reduce_emacs_uint_to_hash_hash): New.
(hashfn_eq, hashfn_equal, hashfn_user_defined): Reduce return values
to hash_hash_t.
(sxhash_string): Remove.  Caller changed to hash_string.
(sxhash_float, sxhash_list, sxhash_vector, sxhash_bool_vector)
(sxhash_bignum): Remove wasteful calls to SXHASH_REDUCE.
(hash_hash_to_fixnum): New.
(Fsxhash_eq, Fsxhash_eql, Fsxhash_equal)
(Fsxhash_equal_including_properties): Convert return values to fixnum.
2024-01-13 20:50:39 +01:00
Mattias Engdegård
11e467eb60 Use key Qunbound instead of hash value hash_unused for free entries
Previously, free hash table entries were indicated by both hash value
hash_unused and key Qunbound; we now rely on the latter only.
This allows us to change the hash representation to one that does not
have an unused value.

* src/lisp.h (hash_unused): Remove.
All uses adapted to calling hash_unused_entry_key_p on the key instead.
The hash values for unused hash table entries are now undefined; all
initialisation and assignment to hash_unused has been removed.
2024-01-13 20:50:39 +01:00
Mattias Engdegård
7ad5d42773 Don't dump Qunbound
The dumper uses a hash table to keep track of dumped objects but as
this clashes with the use of Qunbound for marking unused hash table
entries, don't dump that value at all.  The symbol name is fixed up
after loading.

An alternative solution would be to use a different unique value for
unused entries.

* src/pdumper.c (dump_object_needs_dumping_p): Skip Qunbound.
(dump_vectorlike_generic): New function.
(pdumper_load): Call it.
2024-01-13 20:50:38 +01:00
Mattias Engdegård
68f8bc3111 Change hash_idx_t to int32_t on all platforms
* src/lisp.h (hash_idx_t): Change to int32_t.
* src/fns.c (hash_index_size): Adapt to new index type.
2024-01-13 20:50:38 +01:00
Mattias Engdegård
ed06de52a5 Faster hash table growth, starting at zero size
The algorithms no longer use the rehash_threshold and rehash_size
float constants, but vary depending on size.  In particular, the table
now grows faster, especially from smaller sizes.

The default size is now 0, starting empty, which effectively postpones
allocation until the first insertion (unless make-hash-table was
called with a positive :size); this is a clear gain as long as the
table remains empty.  The first inserted item will use an initial size
of 8 because most tables are small.

* src/fns.c (std_rehash_size, std_rehash_threshold): Remove.
(hash_index_size): Integer-only computation.
(maybe_resize_hash_table): Grow more aggressively.
(Fhash_table_rehash_size, Fhash_table_rehash_threshold):
Use the constants directly.
* src/lisp.h (DEFAULT_HASH_SIZE): New value.
2024-01-13 20:50:38 +01:00
Mattias Engdegård
47502c55b0 ; Reorder struct Lisp_Hash_Table and struct hash_table_test
Mainly for efficiency, to keep frequently used fields together.
2024-01-13 20:50:38 +01:00
Mattias Engdegård
7d93a0147a Share hash table test structs
This saves several words in the hash table object at the cost of an
indirection at runtime.  This seems to be a gain in overall
performance.

FIXME: We cache hash test objects in a rather clumsy way. A better
solution is sought.

* src/lisp.h (struct Lisp_Hash_Table): Use a pointer to the test
struct.  All references adapted.
* src/alloc.c (garbage_collect):
* src/fns.c (struct hash_table_user_test, hash_table_user_tests)
(mark_fns, get_hash_table_user_test): New state for caching test
structs, and functions managing it.
2024-01-13 20:50:38 +01:00
Mattias Engdegård
0a998938ca Use hash_idx_t for storing hash indices
Now hash_idx_t is a typedef for ptrdiff_t so there is no actual code
change, but this allows us to decouple the index width from the Lisp
word size.

* src/lisp.h (hash_idx_t): New typedef for ptrdiff_t.
(struct Lisp_Hash_Table): Use it for indices and sizes:
index, next, table_size, index_size, count and next_free.
All uses adapted.
2024-01-13 20:50:38 +01:00
Mattias Engdegård
3b00255a4c Inlined and specialised hash table look-up
This improves performance in several ways.  Separate functions are
used depending on whether the caller has a hash value computed or not.

* src/fns.c (hash_lookup_with_hash, hash_lookup_get_hash): New.
(hash_lookup): Remove hash return argument.
All callers adapted.

hash_lookup_with_hash hash_hash_t arg
2024-01-13 20:50:38 +01:00
Mattias Engdegård
a3ae5653cf Store hash values as integers instead of Lisp_Object
This improves typing, saves pointless tagging and untagging, and
prepares for further changes. The new typedef hash_hash_t is an alias
for EMACS_UINT, and hash values are still limited to the fixnum range.
We now use hash_unused instead of Qnil to mark unused entries.

* src/lisp.h (hash_hash_t): New typedef for EMACS_UINT.
(hash_unused): New constant.
(struct hash_table_test): `hashfn` now returns
hash_hash_t.  All callers and implementations changed.
(struct Lisp_Hash_Table): Retype hash vector to an array of
hash_hash_t.  All code using it changed accordingly.
(HASH_HASH, hash_from_key):
* src/fns.c (set_hash_index_slot, hash_index_index)
(hash_lookup_with_hash, hash_lookup_get_hash, hash_put):
(hash_lookup, hash_put): Retype hash value arguments
and return values.  All callers adapted.
2024-01-13 20:50:38 +01:00
Mattias Engdegård
fa5c07fc87 Use non-Lisp allocation for internal hash-table vectors
Using xmalloc for allocating these arrays is much cheaper than using
Lisp vectors since they are no longer marked or swept by the GC, and
deallocated much sooner.  This makes GC faster and less frequent, and
improves temporal locality.

Zero-sized tables use NULL for their (0-length) vectors except the
index vector which has size 1 and uses a shared constant static vector
since it cannot be modified anyway.  This makes creation and
destruction of zero-sized hash tables very fast; they consume no
memory outside the base object.

* src/lisp.h (struct Lisp_Hash_Table): Retype the index, next, hash
and key_and_value vectors from Lisp_Object to appropriately typed
arrays (although hash values are still stored as Lisp fixnums).  Add
explicit table_size and index_size members.  All users updated.
* src/alloc.c (gcstat): Add total_hash_table_bytes.
(hash_table_allocated_bytes): New.
(cleanup_vector): Free hash table vectors when sweeping
the object.
(hash_table_alloc_bytes, hash_table_free_bytes): New.
(sweep_vectors): Update gcstat.total_hash_table_bytes.
(total_bytes_of_live_objects): Use it.
(purecopy_hash_table): Adapt allocation of hash table vectors.
(process_mark_stack): No more Lisp slots in the struct to trace.
* src/fns.c (empty_hash_index_vector): New.
(allocate_hash_table): Allocate without automatically GCed slots.
(alloc_larger_vector): Remove.
(make_hash_table, copy_hash_table, maybe_resize_hash_table):
Adapt vector allocation and initialisation.
* src/pdumper.c (hash_table_freeze, hash_table_thaw, dump_hash_table)
(dump_hash_table_contents):
Adapt dumping and loading to field changes.
2024-01-13 20:50:38 +01:00
Mattias Engdegård
49fd4d120d Allow zero hash table size
This avoids any extra allocation for such vectors, including empty
tables read by the Lisp reader, and provides extra safety essentially
for free.

* src/fns.c (make_hash_table): Allow tables to be 0-sized.  The index
will always have at least one entry, to avoid extra look-up costs.
* src/alloc.c (process_mark_stack): Don't mark pure objects,
because empty vectors are pure.
2024-01-13 20:50:38 +01:00
Mattias Engdegård
d3cefd3e98 Leaner hash table dumping and thawing
Only dump the actual data, and the test encoded as an enum.  This
simplifies dumping, makes dump files smaller and saves space at run
time.

* src/lisp.h (hash_table_std_test_t): New enum.
(struct Lisp_Hash_Table): Add frozen_test member, consuming no extra space.
* src/fns.c (hashfn_user_defined): Now static.
(hash_table_test_from_std): New.
(hash_table_rehash): Rename to...
(hash_table_thaw): ...this and rewrite.
* src/pdumper.c (hash_table_contents): Only include actual data, not
unused space.
(hash_table_std_test): New.
(hash_table_freeze): Set frozen_test from test.
(dump_hash_table): Dump frozen_test, not the whole test struct.
Don't bother other dumping fields that can be derived.
2024-01-13 20:50:37 +01:00
Mattias Engdegård
c3d0cc50fa Remove rehash-threshold and rehash-size struct members
These parameters have no visible semantics and are hardly ever used,
so just use the default values for all hash tables.  This saves
memory, shrinks the external representation, and will improve
performance.

* src/fns.c (std_rehash_size, std_rehash_threshold): New.
(hash_index_size): Use std_rehash_threshold.  Remove table argument.
All callers updated.
(make_hash_table): Remove rehash_size and rehash_threshold args.
All callers updated.
(maybe_resize_hash_table)
(Fhash_table_rehash_size, Fhash_table_rehash_threshold):
Use std_rehash_size and std_rehash_threshold.
(Fmake_hash_table): Ignore :rehash-size and :rehash-threshold args.
* src/lisp.h (struct Lisp_Hash_Table):
Remove rehash_size and rehash_threshold fields.
(DEFAULT_REHASH_THRESHOLD, DEFAULT_REHASH_SIZE): Remove.
* src/lread.c (hash_table_from_plist): Don't read rehash-size or
rehash-threshold.
(syms_of_lread): Remove unused symbols.
* src/print.c (print_object): Don't print rehash-size or rehash-threshold.
* src/pdumper.c (dump_hash_table): Don't dump removed fields.
2024-01-13 20:50:37 +01:00
Mattias Engdegård
c6bdc1ea1d Represent hash table weakness as an enum internally
This takes less space (saves an entire word) and is more type-safe.
No change in behaviour.

* src/lisp.h (hash_table_weakness_t): New.
(struct Lisp_Hash_Table): Replace Lisp object `weak` with enum
`weakness`.
* src/fns.c
(keep_entry_p, hash_table_weakness_symbol): New.
(make_hash_table): Retype argument.  All callers updated.
(sweep_weak_table, Fmake_hash_table, Fhash_table_weakness):
* src/alloc.c (purecopy_hash_table, purecopy, process_mark_stack):
* src/pdumper.c (dump_hash_table):
* src/print.c (print_object): Use retyped field.
2024-01-13 20:50:37 +01:00
Mattias Engdegård
3f9c81a87f 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.
2024-01-13 20:50:37 +01:00
Mattias Engdegård
a09619f259 * src/print.c (print_object): Don't print empty hash-table data
Since no data is the default, this preserves bidirectional compatibility.
2024-01-13 20:50:37 +01:00
Mattias Engdegård
4ba6954e69 * src/print.c (print_object): Don't print hash table test if eql.
Since `eql` is the default, this ensures bidirectional compatibility
while reducing the size of the external representation.
2024-01-13 20:50:37 +01:00
Juri Linkov
76904626b3 * lisp/window.el (window-prefix-map): Bind C-x w q to quit-window (bug#13167) 2024-01-13 20:16:42 +02:00
Xiyue Deng
aaf3b63397 Fix typo in lispref "Creating Strings" section
* doc/lispref/strings.texi (String Basics): Fix typo (bug#68375).
2024-01-13 18:08:49 +01:00
Eli Zaretskii
106cd9aafe ; * lisp/textmodes/page.el (page--what-page): Fix last change. 2024-01-13 12:45:10 +02:00
Eli Zaretskii
91b1765cd4 Merge from origin/emacs-29
c494a6e879 Improve documentation of 'emacs_function' in modules
a08e6423cc ; * doc/emacs/fixit.texi (Spelling): Fix last change.
418547162d Improve documentation of Ispell commands
c4b4948845 Don't recommend inverse-video for debugging
2024-01-13 05:36:16 -05:00
Eli Zaretskii
fe7d2bb62f ; Merge from origin/emacs-29
The following commit was skipped:

26eb9d3a8a Fix typo in lispref "Creating Strings" section
2024-01-13 05:36:16 -05:00
Eli Zaretskii
f1736571fa Merge from origin/emacs-29
99efe5c80f Fix count of no-op functions (bug#68375)
0c01f97b73 Wrap @pxref of Abbrevs in parentheses (bug#68375)
70a09325d6 ; Fix last change in widget.texi
63411709a8 ; Fix typos
824cf54951 ; * etc/TODO: Add item to make play-sound non-blocking.
4fadbfe300 Add examples to the Widget manual
1bbb610821 Implement missing functions for custom-icon widget
29af214a75 Fix fontification of cgroup2 in fstab (bug#68367)
2024-01-13 05:36:16 -05:00
Eli Zaretskii
ccc28245c0 ; Merge from origin/emacs-29
The following commit was skipped:

5567ce1a9f Handle package versions that are not version strings
2024-01-13 05:36:15 -05:00
Eli Zaretskii
79a150ffa4 Merge from origin/emacs-29
d58d0fa52f Introduce 'let' using lexical binding in the Lisp Introdu...
1b12397263 ; Don't record multiple versions of use-package
8729a2a10d Fix 'rmail-summary-by-thread'
2a8c00bfc0 * doc/emacs/back.texi: Fix a typo.
2024-01-13 05:36:15 -05:00
Lars Brinkhoff
740953d1a2 Fix 'what-page'
* lisp/textmodes/page.el (page--what-page): Adjust for 1st
line on page, and use 'count-lines' again.  (Bug#68215)

* test/lisp/textmodes/page-tests.el (page-tests-what-page):
Update test.
2024-01-13 12:07:34 +02:00
Eli Zaretskii
c494a6e879 Improve documentation of 'emacs_function' in modules
* doc/lispref/internals.texi (Module Functions): Warn about
accessing the ARGS array in module functions.
2024-01-13 12:01:47 +02:00
Steven Allen
9b8b352ebc Set the 'name' prop in 'define-advice'
In addition to naming the advice function `symbol@name', set
the 'name' property to NAME.
* lisp/emacs-lisp/nadvice.el (define-advice): set the 'name'
property to NAME (requested in Bug#68114).  Fixes Bug#68294.

* doc/lispref/functions.texi (Advising Named Functions): Document
that 'define-advice' installs the advice with the specified name.
2024-01-13 11:43:01 +02:00
kobarity
f2cc8ee2a1 Fix 'python-info-docstring-p' bug in the 2nd line of a buffer
* lisp/progmodes/python.el (python-info-docstring-p): Add
'looking-at-p' check when bobp.
* test/lisp/progmodes/python-tests.el (python-font-lock-operator-1)
(python-font-lock-operator-2): Restoration of ERTs deleted by
mistake.
(python-font-lock-escape-sequence-bytes-newline)
(python-font-lock-escape-sequence-hex-octal)
(python-font-lock-escape-sequence-unicode)
(python-font-lock-raw-escape-sequence): Change 'font-lock-doc-face'
to 'font-lock-string-face' and remove :expected-result :failed.
(python-info-docstring-p-8): New test.  (Bug#68284)
2024-01-13 11:33:19 +02:00
Eli Zaretskii
a08e6423cc ; * doc/emacs/fixit.texi (Spelling): Fix last change. 2024-01-13 11:23:43 +02:00
Stefan Kangas
893829021b Fix NULL dereference in w32notify.c
* src/w32notify.c (start_watching): Return NULL instead of freed
pointer.
(add_watch): Fix NULL dereference.
2024-01-13 10:21:41 +01:00
Stefan Kangas
1bfc7fd33d Prefer AREF in GET_TRANSLATION_TABLE
* src/ccl.c (GET_TRANSLATION_TABLE): Prefer using AREF to depending on
vector internals.
2024-01-13 10:18:03 +01:00
Eli Zaretskii
ec16b69e7f * src/fns.c (maybe_resize_hash_table): Fix EMACS_INT format specifier. 2024-01-13 08:30:50 +02:00
Po Lu
4edb77132d Properly sort results for partial font specs
* src/sfntfont.c (sfntfont_compare_font_entities): New function.
(sfntfont_list): Sort matching font entities by the number of
fields set, and mention why.
2024-01-13 09:51:59 +08:00
Mattias Engdegård
8b7a6d7b6d ; * src/lisp.h (struct Lisp_Hash_Table): Add ASCII art. 2024-01-12 18:03:05 +01:00
Mattias Engdegård
4b7985db11 ; * src/fns.c (Fmake_hash_table): ensure test is a bare symbol 2024-01-12 18:03:05 +01:00
Mattias Engdegård
29e3d1c56f Abstract predicate and constant for unused hash keys
Qunbound is used for many things; using a predicate and constant for
the specific purpose of unused hash entry keys allows us to locate
them and make changes much more easily.

* src/lisp.h (HASH_UNUSED_ENTRY_KEY, hash_unused_entry_key_p):
New constant and function.
* src/comp.c (compile_function, Fcomp__compile_ctxt_to_file):
* src/composite.c (composition_gstring_cache_clear_font):
* src/emacs-module.c (module_global_reference_p):
* src/fns.c (make_hash_table, maybe_resize_hash_table, hash_put)
(hash_remove_from_table, hash_clear, sweep_weak_table, Fmaphash):
* src/json.c (lisp_to_json_nonscalar_1):
* src/minibuf.c (Ftry_completion, Fall_completions, Ftest_completion):
* src/print.c (print, print_object):
Use them.
2024-01-12 18:03:02 +01:00
Mattias Engdegård
484e04efa4 ; * src/alloc.c (purecopy_hash_table): Simplify
Copy the entire struct, then take care of fields needing special
treatment.
2024-01-12 18:02:15 +01:00
Mattias Engdegård
43127e5ec1 Refactor hash table vector reallocation
* src/fns.c (larger_vecalloc): Remove.
(larger_vector): Simplify.
(alloc_larger_vector): New.
(maybe_resize_hash_table): Use alloc_larger_vector as a simpler and
faster replacement for larger_vecalloc.
2024-01-12 18:02:15 +01:00
Mattias Engdegård
462b3e6ae4 Refactor: extract hash and index computations to functions
* src/lisp.h (hash_from_key):
* src/fns.c (hash_index_index): New.
(hash_table_rehash, hash_lookup, hash_remove_from_table):
(maybe_resize_hash_table, hash_put):
* src/composite.c (composition_gstring_put_cache): Use them.
2024-01-12 18:02:15 +01:00