From d923b542aa2d115bb87e72e156be837cea752536 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 11 Jul 2012 10:14:19 +0400 Subject: [PATCH] Avoid call to strlen in fast_c_string_match_ignore_case. * search.c (fast_c_string_match_ignore_case): Change to use length argument. Adjust users accordingly. * lisp.h (fast_c_string_match_ignore_case): Adjust prototype. --- src/ChangeLog | 17 +++++++++++++---- src/font.c | 9 ++++++--- src/font.h | 4 ++-- src/ftfont.c | 4 +++- src/lisp.h | 3 ++- src/lread.c | 2 +- src/search.c | 4 ++-- src/xfont.c | 3 ++- 8 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 7b47636969e..8a6dc8644b8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2012-07-11 Dmitry Antipov + + Avoid call to strlen in fast_c_string_match_ignore_case. + * search.c (fast_c_string_match_ignore_case): Change to use + length argument. Adjust users accordingly. + * lisp.h (fast_c_string_match_ignore_case): Adjust prototype. + 2012-07-11 Paul Eggert Assume rename. @@ -15,10 +22,12 @@ Avoid calls to strlen in font processing functions. * font.c (font_parse_name, font_parse_xlfd, font_parse_fcname) - (font_open_by_name): Changed to use length argument. Adjust + (font_open_by_name): Change to use length argument. Adjust users accordingly. - * font.h (font_open_by_name, font_parse_xlfd): Adjust prototypes. - * xfont.c (xfont_decode_coding_xlfd): Changed to return ptrdiff_t. + * font.h (font_open_by_name, font_parse_xlfd, font_unparse_xlfd): + Adjust prototypes. + * xfont.c (xfont_decode_coding_xlfd, font_unparse_xlfd): + Change to return ptrdiff_t. (xfont_list_pattern, xfont_match): Use length returned by xfont_decode_coding_xlfd. * xfns.c (x_default_font_parameter): Omit useless xstrdup. @@ -107,7 +116,7 @@ Use XCAR and XCDR instead of Fcar and Fcdr where possible. * callint.c, coding.c, doc.c, editfns.c, eval.c, font.c, fontset.c, * frame.c, gnutls.c, minibuf.c, msdos.c, textprop.c, w32fns.c, - * w32menu.c, window.c, xmenu.c: Changed to use XCAR and XCDR + * w32menu.c, window.c, xmenu.c: Change to use XCAR and XCDR where argument type is known to be a Lisp_Cons. 2012-07-10 Tom Tromey diff --git a/src/font.c b/src/font.c index 27abbe25786..bbfda984a4d 100644 --- a/src/font.c +++ b/src/font.c @@ -1199,7 +1199,7 @@ font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font) length), and return the name length. If FONT_SIZE_INDEX of FONT is 0, use PIXEL_SIZE instead. */ -int +ptrdiff_t font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes) { char *p; @@ -2642,15 +2642,18 @@ font_delete_unmatched (Lisp_Object vec, Lisp_Object spec, int size) if (! NILP (Vface_ignored_fonts)) { char name[256]; + ptrdiff_t namelen; Lisp_Object tail, regexp; - if (font_unparse_xlfd (entity, 0, name, 256) >= 0) + namelen = font_unparse_xlfd (entity, 0, name, 256); + if (namelen >= 0) { for (tail = Vface_ignored_fonts; CONSP (tail); tail = XCDR (tail)) { regexp = XCAR (tail); if (STRINGP (regexp) - && fast_c_string_match_ignore_case (regexp, name) >= 0) + && fast_c_string_match_ignore_case (regexp, name, + namelen) >= 0) break; } if (CONSP (tail)) diff --git a/src/font.h b/src/font.h index 11329daa6e7..b4e994397de 100644 --- a/src/font.h +++ b/src/font.h @@ -782,8 +782,8 @@ extern void font_parse_family_registry (Lisp_Object family, Lisp_Object spec); extern int font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font); -extern int font_unparse_xlfd (Lisp_Object font, int pixel_size, - char *name, int bytes); +extern ptrdiff_t font_unparse_xlfd (Lisp_Object font, int pixel_size, + char *name, int bytes); extern int font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int bytes); extern void register_font_driver (struct font_driver *driver, FRAME_PTR f); diff --git a/src/ftfont.c b/src/ftfont.c index 8e322369868..131a27f76e0 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -598,7 +598,9 @@ ftfont_get_charset (Lisp_Object registry) re[j] = '\0'; regexp = make_unibyte_string (re, j); for (i = 0; fc_charset_table[i].name; i++) - if (fast_c_string_match_ignore_case (regexp, fc_charset_table[i].name) >= 0) + if (fast_c_string_match_ignore_case + (regexp, fc_charset_table[i].name, + strlen (fc_charset_table[i].name)) >= 0) break; if (! fc_charset_table[i].name) return -1; diff --git a/src/lisp.h b/src/lisp.h index b4499b0eaaa..5077713451e 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2896,7 +2896,8 @@ extern struct re_pattern_buffer *compile_pattern (Lisp_Object, struct re_registers *, Lisp_Object, int, int); extern ptrdiff_t fast_string_match (Lisp_Object, Lisp_Object); -extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *); +extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *, + ptrdiff_t); extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object); extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, Lisp_Object); diff --git a/src/lread.c b/src/lread.c index c0e4a173eeb..f74d44d12a8 100644 --- a/src/lread.c +++ b/src/lread.c @@ -906,7 +906,7 @@ safe_to_load_p (int fd) if (i >= nbytes || fast_c_string_match_ignore_case (Vbytecomp_version_regexp, - buf + i) < 0) + buf + i, nbytes - i) < 0) safe_p = 0; } if (safe_p) diff --git a/src/search.c b/src/search.c index de95f5a30f4..118cec4af48 100644 --- a/src/search.c +++ b/src/search.c @@ -490,11 +490,11 @@ fast_string_match (Lisp_Object regexp, Lisp_Object string) We assume that STRING contains single-byte characters. */ ptrdiff_t -fast_c_string_match_ignore_case (Lisp_Object regexp, const char *string) +fast_c_string_match_ignore_case (Lisp_Object regexp, + const char *string, ptrdiff_t len) { ptrdiff_t val; struct re_pattern_buffer *bufp; - size_t len = strlen (string); regexp = string_make_unibyte (regexp); re_match_object = Qt; diff --git a/src/xfont.c b/src/xfont.c index 2ba7941c9cb..0443b49de8f 100644 --- a/src/xfont.c +++ b/src/xfont.c @@ -434,7 +434,8 @@ xfont_list_pattern (Display *display, const char *pattern, { elt = XCAR (tail); if (STRINGP (elt) - && fast_c_string_match_ignore_case (elt, indices[i]) >= 0) + && fast_c_string_match_ignore_case (elt, indices[i], + len) >= 0) break; } if (! CONSP (tail)) -- 2.39.2