diff options
| author | Dmitry Antipov | 2015-01-13 07:08:54 +0300 |
|---|---|---|
| committer | Dmitry Antipov | 2015-01-13 07:08:54 +0300 |
| commit | b53b1ca422ff1925f631be511fbec9deb1e4cc33 (patch) | |
| tree | 5d39e0f04440b06fb1350a657839e868aa5996e9 /src | |
| parent | ad9c4a4091df19064a7f7f53bfdb687931e141f6 (diff) | |
| download | emacs-b53b1ca422ff1925f631be511fbec9deb1e4cc33.tar.gz emacs-b53b1ca422ff1925f631be511fbec9deb1e4cc33.zip | |
Consolidate duplicated string matching code.
* search.c (fast_string_match_internal): New function,
consolidated from...
(fast_string_match, fast_string_match_ignore_case): ...functions
which are...
* lisp.h (fast_string_match, fast_string_match_ignore_case):
inlined from here now.
(fast_string_match_internal): Add prototype.
* dired.c (file_name_completion): Use fast_string_match_internal.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 9 | ||||
| -rw-r--r-- | src/dired.c | 21 | ||||
| -rw-r--r-- | src/lisp.h | 17 | ||||
| -rw-r--r-- | src/search.c | 31 |
4 files changed, 36 insertions, 42 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 792407e15e6..48c7370cade 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -18,6 +18,15 @@ | |||
| 18 | * keyboard.c (Ftop_level, Fexit_recursive_edit) | 18 | * keyboard.c (Ftop_level, Fexit_recursive_edit) |
| 19 | (Fabor_recursive_edit): Add noreturn attribute. | 19 | (Fabor_recursive_edit): Add noreturn attribute. |
| 20 | 20 | ||
| 21 | * search.c (fast_string_match_internal): New function, | ||
| 22 | consolidated from... | ||
| 23 | (fast_string_match, fast_string_match_ignore_case): ...functions | ||
| 24 | which are... | ||
| 25 | * lisp.h (fast_string_match, fast_string_match_ignore_case): | ||
| 26 | inlined from here now. | ||
| 27 | (fast_string_match_internal): Add prototype. | ||
| 28 | * dired.c (file_name_completion): Use fast_string_match_internal. | ||
| 29 | |||
| 21 | 2015-01-12 Paul Eggert <eggert@cs.ucla.edu> | 30 | 2015-01-12 Paul Eggert <eggert@cs.ucla.edu> |
| 22 | 31 | ||
| 23 | Port to 32-bit MingGW --with-wide-int | 32 | Port to 32-bit MingGW --with-wide-int |
diff --git a/src/dired.c b/src/dired.c index 00f9a5b0765..9026c5678ef 100644 --- a/src/dired.c +++ b/src/dired.c | |||
| @@ -634,23 +634,14 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, | |||
| 634 | name = DECODE_FILE (name); | 634 | name = DECODE_FILE (name); |
| 635 | 635 | ||
| 636 | { | 636 | { |
| 637 | Lisp_Object regexps; | 637 | Lisp_Object regexps, table = (completion_ignore_case |
| 638 | ? Vascii_canon_table : Qnil); | ||
| 638 | 639 | ||
| 639 | /* Ignore this element if it fails to match all the regexps. */ | 640 | /* Ignore this element if it fails to match all the regexps. */ |
| 640 | if (completion_ignore_case) | 641 | for (regexps = Vcompletion_regexp_list; CONSP (regexps); |
| 641 | { | 642 | regexps = XCDR (regexps)) |
| 642 | for (regexps = Vcompletion_regexp_list; CONSP (regexps); | 643 | if (fast_string_match_internal (XCAR (regexps), name, table) < 0) |
| 643 | regexps = XCDR (regexps)) | 644 | break; |
| 644 | if (fast_string_match_ignore_case (XCAR (regexps), name) < 0) | ||
| 645 | break; | ||
| 646 | } | ||
| 647 | else | ||
| 648 | { | ||
| 649 | for (regexps = Vcompletion_regexp_list; CONSP (regexps); | ||
| 650 | regexps = XCDR (regexps)) | ||
| 651 | if (fast_string_match (XCAR (regexps), name) < 0) | ||
| 652 | break; | ||
| 653 | } | ||
| 654 | 645 | ||
| 655 | if (CONSP (regexps)) | 646 | if (CONSP (regexps)) |
| 656 | continue; | 647 | continue; |
diff --git a/src/lisp.h b/src/lisp.h index 6a39f083a41..a11e61213dc 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -4054,10 +4054,23 @@ struct re_registers; | |||
| 4054 | extern struct re_pattern_buffer *compile_pattern (Lisp_Object, | 4054 | extern struct re_pattern_buffer *compile_pattern (Lisp_Object, |
| 4055 | struct re_registers *, | 4055 | struct re_registers *, |
| 4056 | Lisp_Object, bool, bool); | 4056 | Lisp_Object, bool, bool); |
| 4057 | extern ptrdiff_t fast_string_match (Lisp_Object, Lisp_Object); | 4057 | extern ptrdiff_t fast_string_match_internal (Lisp_Object, Lisp_Object, |
| 4058 | Lisp_Object); | ||
| 4059 | |||
| 4060 | INLINE ptrdiff_t | ||
| 4061 | fast_string_match (Lisp_Object regexp, Lisp_Object string) | ||
| 4062 | { | ||
| 4063 | return fast_string_match_internal (regexp, string, Qnil); | ||
| 4064 | } | ||
| 4065 | |||
| 4066 | INLINE ptrdiff_t | ||
| 4067 | fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string) | ||
| 4068 | { | ||
| 4069 | return fast_string_match_internal (regexp, string, Vascii_canon_table); | ||
| 4070 | } | ||
| 4071 | |||
| 4058 | extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *, | 4072 | extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *, |
| 4059 | ptrdiff_t); | 4073 | ptrdiff_t); |
| 4060 | extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object); | ||
| 4061 | extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t, | 4074 | extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t, |
| 4062 | ptrdiff_t, ptrdiff_t, Lisp_Object); | 4075 | ptrdiff_t, ptrdiff_t, Lisp_Object); |
| 4063 | extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, | 4076 | extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, |
diff --git a/src/search.c b/src/search.c index 0252542a361..e9617985c18 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -459,17 +459,18 @@ matched by parenthesis constructs in the pattern. */) | |||
| 459 | return string_match_1 (regexp, string, start, 1); | 459 | return string_match_1 (regexp, string, start, 1); |
| 460 | } | 460 | } |
| 461 | 461 | ||
| 462 | /* Match REGEXP against STRING, searching all of STRING, | 462 | /* Match REGEXP against STRING using translation table TABLE, |
| 463 | and return the index of the match, or negative on failure. | 463 | searching all of STRING, and return the index of the match, |
| 464 | This does not clobber the match data. */ | 464 | or negative on failure. This does not clobber the match data. */ |
| 465 | 465 | ||
| 466 | ptrdiff_t | 466 | ptrdiff_t |
| 467 | fast_string_match (Lisp_Object regexp, Lisp_Object string) | 467 | fast_string_match_internal (Lisp_Object regexp, Lisp_Object string, |
| 468 | Lisp_Object table) | ||
| 468 | { | 469 | { |
| 469 | ptrdiff_t val; | 470 | ptrdiff_t val; |
| 470 | struct re_pattern_buffer *bufp; | 471 | struct re_pattern_buffer *bufp; |
| 471 | 472 | ||
| 472 | bufp = compile_pattern (regexp, 0, Qnil, | 473 | bufp = compile_pattern (regexp, 0, table, |
| 473 | 0, STRING_MULTIBYTE (string)); | 474 | 0, STRING_MULTIBYTE (string)); |
| 474 | immediate_quit = 1; | 475 | immediate_quit = 1; |
| 475 | re_match_object = string; | 476 | re_match_object = string; |
| @@ -504,26 +505,6 @@ fast_c_string_match_ignore_case (Lisp_Object regexp, | |||
| 504 | return val; | 505 | return val; |
| 505 | } | 506 | } |
| 506 | 507 | ||
| 507 | /* Like fast_string_match but ignore case. */ | ||
| 508 | |||
| 509 | ptrdiff_t | ||
| 510 | fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string) | ||
| 511 | { | ||
| 512 | ptrdiff_t val; | ||
| 513 | struct re_pattern_buffer *bufp; | ||
| 514 | |||
| 515 | bufp = compile_pattern (regexp, 0, Vascii_canon_table, | ||
| 516 | 0, STRING_MULTIBYTE (string)); | ||
| 517 | immediate_quit = 1; | ||
| 518 | re_match_object = string; | ||
| 519 | |||
| 520 | val = re_search (bufp, SSDATA (string), | ||
| 521 | SBYTES (string), 0, | ||
| 522 | SBYTES (string), 0); | ||
| 523 | immediate_quit = 0; | ||
| 524 | return val; | ||
| 525 | } | ||
| 526 | |||
| 527 | /* Match REGEXP against the characters after POS to LIMIT, and return | 508 | /* Match REGEXP against the characters after POS to LIMIT, and return |
| 528 | the number of matched characters. If STRING is non-nil, match | 509 | the number of matched characters. If STRING is non-nil, match |
| 529 | against the characters in it. In that case, POS and LIMIT are | 510 | against the characters in it. In that case, POS and LIMIT are |