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.
This commit is contained in:
Dmitry Antipov 2012-07-11 10:14:19 +04:00
parent 57054ddd44
commit d923b542aa
8 changed files with 31 additions and 15 deletions

View file

@ -1,3 +1,10 @@
2012-07-11 Dmitry Antipov <dmantipov@yandex.ru>
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 <eggert@cs.ucla.edu>
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 <tromey@redhat.com>

View file

@ -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))

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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)

View file

@ -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;

View file

@ -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))