diff options
| author | Karl Heuer | 1998-04-09 18:50:53 +0000 |
|---|---|---|
| committer | Karl Heuer | 1998-04-09 18:50:53 +0000 |
| commit | 67ce527d26eb9b2eab370a495b37867ce40ef50a (patch) | |
| tree | fdf4f8312e5c9282946435e1514901eccb7e5fd1 | |
| parent | 03887dd3884cd7bf42ed18f2fac974653fb628be (diff) | |
| download | emacs-67ce527d26eb9b2eab370a495b37867ce40ef50a.tar.gz emacs-67ce527d26eb9b2eab370a495b37867ce40ef50a.zip | |
(min, max): Make these macros, not functions.
(scan_buffer, boyer_moore): Simplify args to those macros.
| -rw-r--r-- | src/search.c | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/src/search.c b/src/search.c index 6f18fc7d834..ed93d5087d3 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -33,6 +33,9 @@ Boston, MA 02111-1307, USA. */ | |||
| 33 | #include <sys/types.h> | 33 | #include <sys/types.h> |
| 34 | #include "regex.h" | 34 | #include "regex.h" |
| 35 | 35 | ||
| 36 | #define min(a, b) ((a) < (b) ? (a) : (b)) | ||
| 37 | #define max(a, b) ((a) > (b) ? (a) : (b)) | ||
| 38 | |||
| 36 | #define REGEXP_CACHE_SIZE 20 | 39 | #define REGEXP_CACHE_SIZE 20 |
| 37 | 40 | ||
| 38 | /* If the regexp is non-nil, then the buffer contains the compiled form | 41 | /* If the regexp is non-nil, then the buffer contains the compiled form |
| @@ -464,23 +467,6 @@ fast_c_string_match_ignore_case (regexp, string) | |||
| 464 | return val; | 467 | return val; |
| 465 | } | 468 | } |
| 466 | 469 | ||
| 467 | /* max and min. */ | ||
| 468 | |||
| 469 | static int | ||
| 470 | max (a, b) | ||
| 471 | int a, b; | ||
| 472 | { | ||
| 473 | return ((a > b) ? a : b); | ||
| 474 | } | ||
| 475 | |||
| 476 | static int | ||
| 477 | min (a, b) | ||
| 478 | int a, b; | ||
| 479 | { | ||
| 480 | return ((a < b) ? a : b); | ||
| 481 | } | ||
| 482 | |||
| 483 | |||
| 484 | /* The newline cache: remembering which sections of text have no newlines. */ | 470 | /* The newline cache: remembering which sections of text have no newlines. */ |
| 485 | 471 | ||
| 486 | /* If the user has requested newline caching, make sure it's on. | 472 | /* If the user has requested newline caching, make sure it's on. |
| @@ -568,6 +554,7 @@ scan_buffer (target, start, end, count, shortage, allow_quit) | |||
| 568 | examine. */ | 554 | examine. */ |
| 569 | int ceiling_byte = CHAR_TO_BYTE (end) - 1; | 555 | int ceiling_byte = CHAR_TO_BYTE (end) - 1; |
| 570 | int start_byte = CHAR_TO_BYTE (start); | 556 | int start_byte = CHAR_TO_BYTE (start); |
| 557 | int tem; | ||
| 571 | 558 | ||
| 572 | /* If we're looking for a newline, consult the newline cache | 559 | /* If we're looking for a newline, consult the newline cache |
| 573 | to see where we can avoid some scanning. */ | 560 | to see where we can avoid some scanning. */ |
| @@ -593,7 +580,8 @@ scan_buffer (target, start, end, count, shortage, allow_quit) | |||
| 593 | bytes. BUFFER_CEILING_OF returns the last character | 580 | bytes. BUFFER_CEILING_OF returns the last character |
| 594 | position that is contiguous, so the ceiling is the | 581 | position that is contiguous, so the ceiling is the |
| 595 | position after that. */ | 582 | position after that. */ |
| 596 | ceiling_byte = min (BUFFER_CEILING_OF (start_byte), ceiling_byte); | 583 | tem = BUFFER_CEILING_OF (start_byte); |
| 584 | ceiling_byte = min (tem, ceiling_byte); | ||
| 597 | 585 | ||
| 598 | { | 586 | { |
| 599 | /* The termination address of the dumb loop. */ | 587 | /* The termination address of the dumb loop. */ |
| @@ -639,6 +627,7 @@ scan_buffer (target, start, end, count, shortage, allow_quit) | |||
| 639 | /* The last character to check before the next obstacle. */ | 627 | /* The last character to check before the next obstacle. */ |
| 640 | int ceiling_byte = CHAR_TO_BYTE (end); | 628 | int ceiling_byte = CHAR_TO_BYTE (end); |
| 641 | int start_byte = CHAR_TO_BYTE (start); | 629 | int start_byte = CHAR_TO_BYTE (start); |
| 630 | int tem; | ||
| 642 | 631 | ||
| 643 | /* Consult the newline cache, if appropriate. */ | 632 | /* Consult the newline cache, if appropriate. */ |
| 644 | if (target == '\n' && newline_cache) | 633 | if (target == '\n' && newline_cache) |
| @@ -660,7 +649,8 @@ scan_buffer (target, start, end, count, shortage, allow_quit) | |||
| 660 | } | 649 | } |
| 661 | 650 | ||
| 662 | /* Stop scanning before the gap. */ | 651 | /* Stop scanning before the gap. */ |
| 663 | ceiling_byte = max (BUFFER_FLOOR_OF (start_byte - 1), ceiling_byte); | 652 | tem = BUFFER_FLOOR_OF (start_byte - 1); |
| 653 | ceiling_byte = max (tem, ceiling_byte); | ||
| 664 | 654 | ||
| 665 | { | 655 | { |
| 666 | /* The termination address of the dumb loop. */ | 656 | /* The termination address of the dumb loop. */ |
| @@ -1701,14 +1691,22 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt, | |||
| 1701 | QUIT; | 1691 | QUIT; |
| 1702 | pat = base_pat; | 1692 | pat = base_pat; |
| 1703 | limit = pos_byte - dirlen + direction; | 1693 | limit = pos_byte - dirlen + direction; |
| 1704 | limit = ((direction > 0) | 1694 | if (direction > 0) |
| 1705 | ? BUFFER_CEILING_OF (limit) | 1695 | { |
| 1706 | : BUFFER_FLOOR_OF (limit)); | 1696 | limit = BUFFER_CEILING_OF (limit); |
| 1707 | /* LIMIT is now the last (not beyond-last!) value POS_BYTE | 1697 | /* LIMIT is now the last (not beyond-last!) value POS_BYTE |
| 1708 | can take on without hitting edge of buffer or the gap. */ | 1698 | can take on without hitting edge of buffer or the gap. */ |
| 1709 | limit = ((direction > 0) | 1699 | limit = min (limit, pos_byte + 20000); |
| 1710 | ? min (lim_byte - 1, min (limit, pos_byte + 20000)) | 1700 | limit = min (limit, lim_byte - 1); |
| 1711 | : max (lim_byte, max (limit, pos_byte - 20000))); | 1701 | } |
| 1702 | else | ||
| 1703 | { | ||
| 1704 | limit = BUFFER_FLOOR_OF (limit); | ||
| 1705 | /* LIMIT is now the last (not beyond-last!) value POS_BYTE | ||
| 1706 | can take on without hitting edge of buffer or the gap. */ | ||
| 1707 | limit = max (limit, pos_byte - 20000); | ||
| 1708 | limit = max (limit, lim_byte); | ||
| 1709 | } | ||
| 1712 | tail_end = BUFFER_CEILING_OF (pos_byte) + 1; | 1710 | tail_end = BUFFER_CEILING_OF (pos_byte) + 1; |
| 1713 | tail_end_ptr = BYTE_POS_ADDR (tail_end); | 1711 | tail_end_ptr = BYTE_POS_ADDR (tail_end); |
| 1714 | 1712 | ||