diff options
| author | Dmitry Antipov | 2012-07-10 11:59:31 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2012-07-10 11:59:31 +0400 |
| commit | cb1caeaf2ba26df05e8f9bcd4aa63203cef781fb (patch) | |
| tree | 78cbdfcc89455a0ab097eb1fd16c029d0ac48e0d | |
| parent | d02eb359e68a083fc55f0355b86df2a07b8d570d (diff) | |
| download | emacs-cb1caeaf2ba26df05e8f9bcd4aa63203cef781fb.tar.gz emacs-cb1caeaf2ba26df05e8f9bcd4aa63203cef781fb.zip | |
Avoid calls to strlen in miscellaneous functions.
* buffer.c (init_buffer): Use precalculated len, adjust if needed.
* font.c (Ffont_xlfd_name): Likewise. Change to call make_string.
* lread.c (openp): Likewise.
| -rw-r--r-- | src/ChangeLog | 9 | ||||
| -rw-r--r-- | src/buffer.c | 3 | ||||
| -rw-r--r-- | src/font.c | 9 | ||||
| -rw-r--r-- | src/lread.c | 22 |
4 files changed, 28 insertions, 15 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index de0f729f915..5815c83ae1e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,11 +1,18 @@ | |||
| 1 | 2012-07-10 Dmitry Antipov <dmantipov@yandex.ru> | 1 | 2012-07-10 Dmitry Antipov <dmantipov@yandex.ru> |
| 2 | 2 | ||
| 3 | Avoid calls to strlen in miscellaneous functions. | ||
| 4 | * buffer.c (init_buffer): Use precalculated len, adjust if needed. | ||
| 5 | * font.c (Ffont_xlfd_name): Likewise. Change to call make_string. | ||
| 6 | * lread.c (openp): Likewise. | ||
| 7 | |||
| 8 | 2012-07-10 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 9 | |||
| 3 | Avoid calls to strlen in path processing functions. | 10 | Avoid calls to strlen in path processing functions. |
| 4 | * fileio.c (file_name_as_directory): Add comment. Change to add | 11 | * fileio.c (file_name_as_directory): Add comment. Change to add |
| 5 | srclen argument and return the length of result. Adjust users | 12 | srclen argument and return the length of result. Adjust users |
| 6 | accordingly. | 13 | accordingly. |
| 7 | (directory_file_name): Fix comment. Change to add srclen argument, | 14 | (directory_file_name): Fix comment. Change to add srclen argument, |
| 8 | swap 1nd and 2st arguments to obey the common convention. Adjust | 15 | swap 1st and 2nd arguments to obey the common convention. Adjust |
| 9 | users accordingly. | 16 | users accordingly. |
| 10 | * filelock.c (fill_in_lock_file_name): Avoid calls to strlen. | 17 | * filelock.c (fill_in_lock_file_name): Avoid calls to strlen. |
| 11 | 18 | ||
diff --git a/src/buffer.c b/src/buffer.c index 28cede3916c..4999639128d 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -5091,9 +5091,10 @@ init_buffer (void) | |||
| 5091 | fatal ("`get_current_dir_name' failed: %s\n", strerror (errno)); | 5091 | fatal ("`get_current_dir_name' failed: %s\n", strerror (errno)); |
| 5092 | pwd[len] = DIRECTORY_SEP; | 5092 | pwd[len] = DIRECTORY_SEP; |
| 5093 | pwd[len + 1] = '\0'; | 5093 | pwd[len + 1] = '\0'; |
| 5094 | len++; | ||
| 5094 | } | 5095 | } |
| 5095 | 5096 | ||
| 5096 | BVAR (current_buffer, directory) = make_unibyte_string (pwd, strlen (pwd)); | 5097 | BVAR (current_buffer, directory) = make_unibyte_string (pwd, len); |
| 5097 | if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) | 5098 | if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) |
| 5098 | /* At this moment, we still don't know how to decode the | 5099 | /* At this moment, we still don't know how to decode the |
| 5099 | directory name. So, we keep the bytes in multibyte form so | 5100 | directory name. So, we keep the bytes in multibyte form so |
diff --git a/src/font.c b/src/font.c index 4f0f814a583..1eca1c2eb29 100644 --- a/src/font.c +++ b/src/font.c | |||
| @@ -4218,7 +4218,7 @@ the consecutive wildcards are folded into one. */) | |||
| 4218 | (Lisp_Object font, Lisp_Object fold_wildcards) | 4218 | (Lisp_Object font, Lisp_Object fold_wildcards) |
| 4219 | { | 4219 | { |
| 4220 | char name[256]; | 4220 | char name[256]; |
| 4221 | int pixel_size = 0; | 4221 | int namelen, pixel_size = 0; |
| 4222 | 4222 | ||
| 4223 | CHECK_FONT (font); | 4223 | CHECK_FONT (font); |
| 4224 | 4224 | ||
| @@ -4232,11 +4232,13 @@ the consecutive wildcards are folded into one. */) | |||
| 4232 | if (NILP (fold_wildcards)) | 4232 | if (NILP (fold_wildcards)) |
| 4233 | return font_name; | 4233 | return font_name; |
| 4234 | strcpy (name, SSDATA (font_name)); | 4234 | strcpy (name, SSDATA (font_name)); |
| 4235 | namelen = SBYTES (font_name); | ||
| 4235 | goto done; | 4236 | goto done; |
| 4236 | } | 4237 | } |
| 4237 | pixel_size = XFONT_OBJECT (font)->pixel_size; | 4238 | pixel_size = XFONT_OBJECT (font)->pixel_size; |
| 4238 | } | 4239 | } |
| 4239 | if (font_unparse_xlfd (font, pixel_size, name, 256) < 0) | 4240 | namelen = font_unparse_xlfd (font, pixel_size, name, 256); |
| 4241 | if (namelen < 0) | ||
| 4240 | return Qnil; | 4242 | return Qnil; |
| 4241 | done: | 4243 | done: |
| 4242 | if (! NILP (fold_wildcards)) | 4244 | if (! NILP (fold_wildcards)) |
| @@ -4246,11 +4248,12 @@ the consecutive wildcards are folded into one. */) | |||
| 4246 | while ((p1 = strstr (p0, "-*-*"))) | 4248 | while ((p1 = strstr (p0, "-*-*"))) |
| 4247 | { | 4249 | { |
| 4248 | strcpy (p1, p1 + 2); | 4250 | strcpy (p1, p1 + 2); |
| 4251 | namelen -= 2; | ||
| 4249 | p0 = p1; | 4252 | p0 = p1; |
| 4250 | } | 4253 | } |
| 4251 | } | 4254 | } |
| 4252 | 4255 | ||
| 4253 | return build_string (name); | 4256 | return make_string (name, namelen); |
| 4254 | } | 4257 | } |
| 4255 | 4258 | ||
| 4256 | DEFUN ("clear-font-cache", Fclear_font_cache, Sclear_font_cache, 0, 0, 0, | 4259 | DEFUN ("clear-font-cache", Fclear_font_cache, Sclear_font_cache, 0, 0, 0, |
diff --git a/src/lread.c b/src/lread.c index c69190c37b6..900a25372d8 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -1489,7 +1489,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto | |||
| 1489 | for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes; | 1489 | for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes; |
| 1490 | CONSP (tail); tail = XCDR (tail)) | 1490 | CONSP (tail); tail = XCDR (tail)) |
| 1491 | { | 1491 | { |
| 1492 | ptrdiff_t lsuffix = SBYTES (XCAR (tail)); | 1492 | ptrdiff_t fnlen, lsuffix = SBYTES (XCAR (tail)); |
| 1493 | Lisp_Object handler; | 1493 | Lisp_Object handler; |
| 1494 | int exists; | 1494 | int exists; |
| 1495 | 1495 | ||
| @@ -1499,20 +1499,22 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto | |||
| 1499 | && SREF (filename, 0) == '/' | 1499 | && SREF (filename, 0) == '/' |
| 1500 | && SREF (filename, 1) == ':') | 1500 | && SREF (filename, 1) == ':') |
| 1501 | { | 1501 | { |
| 1502 | strncpy (fn, SSDATA (filename) + 2, | 1502 | fnlen = SBYTES (filename) - 2; |
| 1503 | SBYTES (filename) - 2); | 1503 | strncpy (fn, SSDATA (filename) + 2, fnlen); |
| 1504 | fn[SBYTES (filename) - 2] = 0; | 1504 | fn[fnlen] = '\0'; |
| 1505 | } | 1505 | } |
| 1506 | else | 1506 | else |
| 1507 | { | 1507 | { |
| 1508 | strncpy (fn, SSDATA (filename), | 1508 | fnlen = SBYTES (filename); |
| 1509 | SBYTES (filename)); | 1509 | strncpy (fn, SSDATA (filename), fnlen); |
| 1510 | fn[SBYTES (filename)] = 0; | 1510 | fn[fnlen] = '\0'; |
| 1511 | } | 1511 | } |
| 1512 | 1512 | ||
| 1513 | if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */ | 1513 | if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */ |
| 1514 | strncat (fn, SSDATA (XCAR (tail)), lsuffix); | 1514 | { |
| 1515 | 1515 | strncat (fn, SSDATA (XCAR (tail)), lsuffix); | |
| 1516 | fnlen += lsuffix; | ||
| 1517 | } | ||
| 1516 | /* Check that the file exists and is not a directory. */ | 1518 | /* Check that the file exists and is not a directory. */ |
| 1517 | /* We used to only check for handlers on non-absolute file names: | 1519 | /* We used to only check for handlers on non-absolute file names: |
| 1518 | if (absolute) | 1520 | if (absolute) |
| @@ -1521,7 +1523,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto | |||
| 1521 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); | 1523 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); |
| 1522 | It's not clear why that was the case and it breaks things like | 1524 | It's not clear why that was the case and it breaks things like |
| 1523 | (load "/bar.el") where the file is actually "/bar.el.gz". */ | 1525 | (load "/bar.el") where the file is actually "/bar.el.gz". */ |
| 1524 | string = build_string (fn); | 1526 | string = make_string (fn, fnlen); |
| 1525 | handler = Ffind_file_name_handler (string, Qfile_exists_p); | 1527 | handler = Ffind_file_name_handler (string, Qfile_exists_p); |
| 1526 | if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate)) | 1528 | if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate)) |
| 1527 | { | 1529 | { |