[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r109010: Avoid calls to strlen in fon
From: |
Dmitry Antipov |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r109010: Avoid calls to strlen in font processing functions. |
Date: |
Wed, 11 Jul 2012 08:31:53 +0400 |
User-agent: |
Bazaar (2.5.0) |
------------------------------------------------------------
revno: 109010
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Wed 2012-07-11 08:31:53 +0400
message:
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
users accordingly.
* font.h (font_open_by_name, font_parse_xlfd): Adjust prototypes.
* xfont.c (xfont_decode_coding_xlfd): Changed 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.
modified:
src/ChangeLog
src/font.c
src/font.h
src/fontset.c
src/frame.c
src/w32fns.c
src/xfns.c
src/xfont.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2012-07-11 02:29:13 +0000
+++ b/src/ChangeLog 2012-07-11 04:31:53 +0000
@@ -1,3 +1,15 @@
+2012-07-11 Dmitry Antipov <address@hidden>
+
+ 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
+ users accordingly.
+ * font.h (font_open_by_name, font_parse_xlfd): Adjust prototypes.
+ * xfont.c (xfont_decode_coding_xlfd): Changed 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.
+
2012-07-11 Glenn Morris <address@hidden>
* s/darwin.h, s/freebsd.h, s/netbsd.h:
=== modified file 'src/font.c'
--- a/src/font.c 2012-07-10 16:53:26 +0000
+++ b/src/font.c 2012-07-11 04:31:53 +0000
@@ -739,7 +739,7 @@
static int parse_matrix (const char *);
static int font_expand_wildcards (Lisp_Object *, int);
-static int font_parse_name (char *, Lisp_Object);
+static int font_parse_name (char *, ptrdiff_t, Lisp_Object);
/* An enumerator for each field of an XLFD font name. */
enum xlfd_field_index
@@ -1019,9 +1019,8 @@
a fully specified XLFD. */
int
-font_parse_xlfd (char *name, Lisp_Object font)
+font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font)
{
- ptrdiff_t len = strlen (name);
int i, j, n;
char *f[XLFD_LAST_INDEX + 1];
Lisp_Object val;
@@ -1336,12 +1335,11 @@
This function tries to guess which format it is. */
static int
-font_parse_fcname (char *name, Lisp_Object font)
+font_parse_fcname (char *name, ptrdiff_t len, Lisp_Object font)
{
char *p, *q;
char *size_beg = NULL, *size_end = NULL;
char *props_beg = NULL, *family_end = NULL;
- ptrdiff_t len = strlen (name);
if (len == 0)
return -1;
@@ -1694,11 +1692,11 @@
0. Otherwise return -1. */
static int
-font_parse_name (char *name, Lisp_Object font)
+font_parse_name (char *name, ptrdiff_t namelen, Lisp_Object font)
{
if (name[0] == '-' || strchr (name, '*') || strchr (name, '?'))
- return font_parse_xlfd (name, font);
- return font_parse_fcname (name, font);
+ return font_parse_xlfd (name, namelen, font);
+ return font_parse_fcname (name, namelen, font);
}
@@ -2987,7 +2985,7 @@
Lisp_Object spec = Ffont_spec (0, NULL);
CHECK_STRING (font_name);
- if (font_parse_name (SSDATA (font_name), spec) == -1)
+ if (font_parse_name (SSDATA (font_name), SBYTES (font_name), spec) == -1)
return Qnil;
font_put_extra (spec, QCname, font_name);
font_put_extra (spec, QCuser_spec, font_name);
@@ -3359,13 +3357,13 @@
found, return Qnil. */
Lisp_Object
-font_open_by_name (FRAME_PTR f, const char *name)
+font_open_by_name (FRAME_PTR f, const char *name, ptrdiff_t len)
{
Lisp_Object args[2];
Lisp_Object spec, ret;
args[0] = QCname;
- args[1] = make_unibyte_string (name, strlen (name));
+ args[1] = make_unibyte_string (name, len);
spec = Ffont_spec (2, args);
ret = font_open_by_spec (f, spec);
/* Do not lose name originally put in. */
@@ -3872,7 +3870,7 @@
if (EQ (key, QCname))
{
CHECK_STRING (val);
- font_parse_name (SSDATA (val), spec);
+ font_parse_name (SSDATA (val), SBYTES (val), spec);
font_put_extra (spec, key, val);
}
else
@@ -4887,7 +4885,7 @@
if (fontset >= 0)
name = fontset_ascii (fontset);
- font_object = font_open_by_name (f, SSDATA (name));
+ font_object = font_open_by_name (f, SSDATA (name), SBYTES (name));
}
else if (FONT_OBJECT_P (name))
font_object = name;
=== modified file 'src/font.h'
--- a/src/font.h 2012-07-03 18:24:42 +0000
+++ b/src/font.h 2012-07-11 04:31:53 +0000
@@ -771,7 +771,7 @@
extern void font_done_for_face (FRAME_PTR f, struct face *face);
extern Lisp_Object font_open_by_spec (FRAME_PTR f, Lisp_Object spec);
-extern Lisp_Object font_open_by_name (FRAME_PTR f, const char *name);
+extern Lisp_Object font_open_by_name (FRAME_PTR f, const char *name, ptrdiff_t
len);
extern Lisp_Object font_intern_prop (const char *str, ptrdiff_t len,
int force_symbol);
@@ -781,7 +781,7 @@
Lisp_Object registry,
Lisp_Object spec);
-extern int font_parse_xlfd (char *name, Lisp_Object font);
+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 int font_unparse_fcname (Lisp_Object font, int pixel_size,
=== modified file 'src/fontset.c'
--- a/src/fontset.c 2012-07-10 16:53:26 +0000
+++ b/src/fontset.c 2012-07-11 04:31:53 +0000
@@ -1646,7 +1646,7 @@
char xlfd[256];
int len;
- if (font_parse_xlfd (SSDATA (name), font_spec) < 0)
+ if (font_parse_xlfd (SSDATA (name), SBYTES (name), font_spec) < 0)
error ("Fontset name must be in XLFD format");
short_name = AREF (font_spec, FONT_REGISTRY_INDEX);
if (strncmp (SSDATA (SYMBOL_NAME (short_name)), "fontset-", 8)
=== modified file 'src/frame.c'
--- a/src/frame.c 2012-07-10 21:48:34 +0000
+++ b/src/frame.c 2012-07-11 04:31:53 +0000
@@ -3167,7 +3167,7 @@
fontset = fs_query_fontset (arg, 0);
if (fontset < 0)
{
- font_object = font_open_by_name (f, SSDATA (arg));
+ font_object = font_open_by_name (f, SSDATA (arg), SBYTES (arg));
if (NILP (font_object))
error ("Font `%s' is not defined", SSDATA (arg));
arg = AREF (font_object, FONT_NAME_INDEX);
@@ -3176,7 +3176,7 @@
{
Lisp_Object ascii_font = fontset_ascii (fontset);
- font_object = font_open_by_name (f, SSDATA (ascii_font));
+ font_object = font_open_by_name (f, SSDATA (ascii_font), SBYTES
(ascii_font));
if (NILP (font_object))
error ("Font `%s' is not defined", SDATA (arg));
arg = AREF (font_object, FONT_NAME_INDEX);
=== modified file 'src/w32fns.c'
--- a/src/w32fns.c 2012-07-10 16:53:26 +0000
+++ b/src/w32fns.c 2012-07-11 04:31:53 +0000
@@ -4036,7 +4036,7 @@
for (i = 0; names[i]; i++)
{
- font = font_open_by_name (f, names[i]);
+ font = font_open_by_name (f, names[i], strlen (names[i]));
if (! NILP (font))
break;
}
=== modified file 'src/xfns.c'
--- a/src/xfns.c 2012-07-10 08:43:46 +0000
+++ b/src/xfns.c 2012-07-11 04:31:53 +0000
@@ -2956,11 +2956,7 @@
read yet. */
const char *system_font = xsettings_get_system_font ();
if (system_font)
- {
- char *name = xstrdup (system_font);
- font = font_open_by_name (f, name);
- xfree (name);
- }
+ font = font_open_by_name (f, system_font, strlen (system_font));
}
if (NILP (font))
@@ -2990,7 +2986,7 @@
for (i = 0; names[i]; i++)
{
- font = font_open_by_name (f, names[i]);
+ font = font_open_by_name (f, names[i], strlen (names[i]));
if (! NILP (font))
break;
}
=== modified file 'src/xfont.c'
--- a/src/xfont.c 2012-07-06 20:49:23 +0000
+++ b/src/xfont.c 2012-07-11 04:31:53 +0000
@@ -174,7 +174,7 @@
XLFD is NULL terminated. The caller must assure that OUTPUT is at
least twice (plus 1) as large as XLFD. */
-static int
+static ptrdiff_t
xfont_decode_coding_xlfd (char *xlfd, int len, char *output)
{
char *p0 = xlfd, *p1 = output;
@@ -397,13 +397,14 @@
for (i = 0; i < num_fonts; i++)
{
+ ptrdiff_t len;
Lisp_Object entity;
if (i > 0 && xstrcasecmp (indices[i - 1], indices[i]) == 0)
continue;
entity = font_make_entity ();
- xfont_decode_coding_xlfd (indices[i], -1, buf);
- if (font_parse_xlfd (buf, entity) < 0)
+ len = xfont_decode_coding_xlfd (indices[i], -1, buf);
+ if (font_parse_xlfd (buf, len, entity) < 0)
continue;
ASET (entity, FONT_TYPE_INDEX, Qx);
/* Avoid auto-scaled fonts. */
@@ -604,10 +605,11 @@
string. We must avoid such a name. */
if (*s)
{
+ ptrdiff_t len;
entity = font_make_entity ();
ASET (entity, FONT_TYPE_INDEX, Qx);
- xfont_decode_coding_xlfd (s, -1, name);
- if (font_parse_xlfd (name, entity) < 0)
+ len = xfont_decode_coding_xlfd (s, -1, name);
+ if (font_parse_xlfd (name, len, entity) < 0)
entity = Qnil;
}
XFree (s);
@@ -796,7 +798,7 @@
ASET (font_object, FONT_TYPE_INDEX, Qx);
if (STRINGP (fullname))
{
- font_parse_xlfd (SSDATA (fullname), font_object);
+ font_parse_xlfd (SSDATA (fullname), SBYTES (fullname), font_object);
ASET (font_object, FONT_NAME_INDEX, fullname);
}
else
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r109010: Avoid calls to strlen in font processing functions.,
Dmitry Antipov <=