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 /src/lread.c | |
| 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.
Diffstat (limited to 'src/lread.c')
| -rw-r--r-- | src/lread.c | 22 |
1 files changed, 12 insertions, 10 deletions
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 | { |