Improve the fix for bug#51864

* src/xfaces.c (face_at_buffer_position): Call
FACE_FROM_ID_OR_NULL just once.
(face_at_string_position): Make sure we have a usable base face.
This commit is contained in:
Eli Zaretskii 2021-11-21 09:52:43 +02:00
parent f050719282
commit f2730520ce

View file

@ -4841,7 +4841,7 @@ lookup_named_face (struct window *w, struct frame *f,
/* Return the display face-id of the basic face whose canonical face-id
is FACE_ID. The return value will usually simply be FACE_ID, unless that
basic face has bee remapped via Vface_remapping_alist. This function is
basic face has been remapped via Vface_remapping_alist. This function is
conservative: if something goes wrong, it will simply return FACE_ID
rather than signal an error. Window W, if non-NULL, is used to filter
face specifications for remapping. */
@ -6372,20 +6372,16 @@ face_at_buffer_position (struct window *w, ptrdiff_t pos,
int face_id;
if (base_face_id >= 0)
{
face_id = base_face_id;
/* Make sure the base face ID is usable: if someone freed the
cached faces since we've looked up the base face, we need
to look it up again. */
if (!FACE_FROM_ID_OR_NULL (f, face_id))
face_id = lookup_basic_face (w, f, DEFAULT_FACE_ID);
}
face_id = base_face_id;
else if (NILP (Vface_remapping_alist))
face_id = DEFAULT_FACE_ID;
else
face_id = lookup_basic_face (w, f, DEFAULT_FACE_ID);
default_face = FACE_FROM_ID_OR_NULL (f, face_id);
/* Make sure the default face ID is usable: if someone freed the
cached faces since we've looked up these faces, we need to look
them up again. */
if (!default_face)
default_face = FACE_FROM_ID (f,
lookup_basic_face (w, f, DEFAULT_FACE_ID));
@ -6573,7 +6569,9 @@ face_at_string_position (struct window *w, Lisp_Object string,
else
*endptr = -1;
base_face = FACE_FROM_ID (f, base_face_id);
base_face = FACE_FROM_ID_OR_NULL (f, base_face_id);
if (!base_face)
base_face = FACE_FROM_ID (f, lookup_basic_face (w, f, DEFAULT_FACE_ID));
/* Optimize the default case that there is no face property. */
if (NILP (prop)