Mercurial > emacs
comparison src/search.c @ 21457:8c6ea32aadfa
(min, max): Make these macros, not functions.
(scan_buffer, boyer_moore): Simplify args to those macros.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Thu, 09 Apr 1998 18:50:53 +0000 |
parents | aba5e1c3328b |
children | fa9ff387d260 |
comparison
equal
deleted
inserted
replaced
21456:c0496e62b737 | 21457:8c6ea32aadfa |
---|---|
30 #include "blockinput.h" | 30 #include "blockinput.h" |
31 #include "intervals.h" | 31 #include "intervals.h" |
32 | 32 |
33 #include <sys/types.h> | 33 #include <sys/types.h> |
34 #include "regex.h" | 34 #include "regex.h" |
35 | |
36 #define min(a, b) ((a) < (b) ? (a) : (b)) | |
37 #define max(a, b) ((a) > (b) ? (a) : (b)) | |
35 | 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 |
39 of that regexp, suitable for searching. */ | 42 of that regexp, suitable for searching. */ |
462 val = re_search (bufp, string, len, 0, len, 0); | 465 val = re_search (bufp, string, len, 0, len, 0); |
463 immediate_quit = 0; | 466 immediate_quit = 0; |
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. |
487 Otherwise, make sure it's off. | 473 Otherwise, make sure it's off. |
488 This is our cheezy way of associating an action with the change of | 474 This is our cheezy way of associating an action with the change of |
566 the position of the last character before the next such | 552 the position of the last character before the next such |
567 obstacle --- the last character the dumb search loop should | 553 obstacle --- the last character the dumb search loop should |
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. */ |
574 if (target == '\n' && newline_cache) | 561 if (target == '\n' && newline_cache) |
575 { | 562 { |
591 | 578 |
592 /* The dumb loop can only scan text stored in contiguous | 579 /* The dumb loop can only scan text stored in contiguous |
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. */ |
600 register unsigned char *ceiling_addr | 588 register unsigned char *ceiling_addr |
601 = BYTE_POS_ADDR (ceiling_byte) + 1; | 589 = BYTE_POS_ADDR (ceiling_byte) + 1; |
637 while (start > end) | 625 while (start > end) |
638 { | 626 { |
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) |
645 { | 634 { |
646 int next_change; | 635 int next_change; |
658 next_change is the position of the next known region. */ | 647 next_change is the position of the next known region. */ |
659 ceiling_byte = max (next_change, ceiling_byte); | 648 ceiling_byte = max (next_change, ceiling_byte); |
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. */ |
667 register unsigned char *ceiling_addr = BYTE_POS_ADDR (ceiling_byte); | 657 register unsigned char *ceiling_addr = BYTE_POS_ADDR (ceiling_byte); |
668 register unsigned char *cursor = BYTE_POS_ADDR (start_byte - 1); | 658 register unsigned char *cursor = BYTE_POS_ADDR (start_byte - 1); |
1699 return (n * (0 - direction)); | 1689 return (n * (0 - direction)); |
1700 /* First we do the part we can by pointers (maybe nothing) */ | 1690 /* First we do the part we can by pointers (maybe nothing) */ |
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 |
1715 if ((limit - pos_byte) * direction > 20) | 1713 if ((limit - pos_byte) * direction > 20) |
1716 { | 1714 { |