diff options
| author | Dmitry Antipov | 2013-08-29 11:03:18 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2013-08-29 11:03:18 +0400 |
| commit | d2b368135803170fc2d1f65237b7ef22676f9ecb (patch) | |
| tree | 366956b20df8e76e561878824bd5e96fa5936d85 /src | |
| parent | e8dfd19797fa7224ae726a8be78726fefd260c0e (diff) | |
| download | emacs-d2b368135803170fc2d1f65237b7ef22676f9ecb.tar.gz emacs-d2b368135803170fc2d1f65237b7ef22676f9ecb.zip | |
Hook scanning and indentation functions to find_newline. This helps
to avoid duplicated code and renders more respect to newline cache.
* lisp.h (scan_newline): Prefer ptrdiff_t to EMACS_INT.
* cmds.c (Fforward_line):
* indent.c (scan_for_column, Fcurrent_indentation, indented_beyond_p):
Use find_newline and avoid unnecessary point movements.
* search.c (scan_newline): Implement on top of find_newline.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 10 | ||||
| -rw-r--r-- | src/cmds.c | 18 | ||||
| -rw-r--r-- | src/indent.c | 38 | ||||
| -rw-r--r-- | src/lisp.h | 4 | ||||
| -rw-r--r-- | src/search.c | 86 |
5 files changed, 40 insertions, 116 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 9e62a8e08a4..2105391755b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2013-08-29 Dmitry Antipov <dmantipov@yandex.ru> | ||
| 2 | |||
| 3 | Hook scanning and indentation functions to find_newline. This helps | ||
| 4 | to avoid duplicated code and renders more respect to newline cache. | ||
| 5 | * lisp.h (scan_newline): Prefer ptrdiff_t to EMACS_INT. | ||
| 6 | * cmds.c (Fforward_line): | ||
| 7 | * indent.c (scan_for_column, Fcurrent_indentation, indented_beyond_p): | ||
| 8 | Use find_newline and avoid unnecessary point movements. | ||
| 9 | * search.c (scan_newline): Implement on top of find_newline. | ||
| 10 | |||
| 1 | 2013-08-28 Stefan Monnier <monnier@iro.umontreal.ca> | 11 | 2013-08-28 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 12 | ||
| 3 | * eval.c (Ffuncall): Fix handling of ((lambda ..) ..) in lexically | 13 | * eval.c (Ffuncall): Fix handling of ((lambda ..) ..) in lexically |
diff --git a/src/cmds.c b/src/cmds.c index ce91877f85e..ee3be79a0ab 100644 --- a/src/cmds.c +++ b/src/cmds.c | |||
| @@ -121,9 +121,7 @@ With positive N, a non-empty line at the end counts as one line | |||
| 121 | successfully moved (for the return value). */) | 121 | successfully moved (for the return value). */) |
| 122 | (Lisp_Object n) | 122 | (Lisp_Object n) |
| 123 | { | 123 | { |
| 124 | ptrdiff_t opoint = PT, opoint_byte = PT_BYTE; | 124 | ptrdiff_t opoint = PT, pos, pos_byte, shortage, count; |
| 125 | ptrdiff_t pos, pos_byte; | ||
| 126 | EMACS_INT count, shortage; | ||
| 127 | 125 | ||
| 128 | if (NILP (n)) | 126 | if (NILP (n)) |
| 129 | count = 1; | 127 | count = 1; |
| @@ -134,16 +132,12 @@ successfully moved (for the return value). */) | |||
| 134 | } | 132 | } |
| 135 | 133 | ||
| 136 | if (count <= 0) | 134 | if (count <= 0) |
| 137 | shortage = scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1, 1); | 135 | pos = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1, |
| 136 | &shortage, &pos_byte, 1); | ||
| 138 | else | 137 | else |
| 139 | shortage = scan_newline (PT, PT_BYTE, ZV, ZV_BYTE, count, 1); | 138 | pos = find_newline (PT, PT_BYTE, ZV, ZV_BYTE, count, |
| 140 | 139 | &shortage, &pos_byte, 1); | |
| 141 | /* Since scan_newline does TEMP_SET_PT_BOTH, | 140 | |
| 142 | and we want to set PT "for real", | ||
| 143 | go back to the old point and then come back here. */ | ||
| 144 | pos = PT; | ||
| 145 | pos_byte = PT_BYTE; | ||
| 146 | TEMP_SET_PT_BOTH (opoint, opoint_byte); | ||
| 147 | SET_PT_BOTH (pos, pos_byte); | 141 | SET_PT_BOTH (pos, pos_byte); |
| 148 | 142 | ||
| 149 | if (shortage > 0 | 143 | if (shortage > 0 |
diff --git a/src/indent.c b/src/indent.c index 6aaf86579d7..891b42788ed 100644 --- a/src/indent.c +++ b/src/indent.c | |||
| @@ -510,15 +510,10 @@ scan_for_column (ptrdiff_t *endpos, EMACS_INT *goalcol, ptrdiff_t *prevcol) | |||
| 510 | register ptrdiff_t col = 0, prev_col = 0; | 510 | register ptrdiff_t col = 0, prev_col = 0; |
| 511 | EMACS_INT goal = goalcol ? *goalcol : MOST_POSITIVE_FIXNUM; | 511 | EMACS_INT goal = goalcol ? *goalcol : MOST_POSITIVE_FIXNUM; |
| 512 | ptrdiff_t end = endpos ? *endpos : PT; | 512 | ptrdiff_t end = endpos ? *endpos : PT; |
| 513 | ptrdiff_t scan, scan_byte; | 513 | ptrdiff_t scan, scan_byte, next_boundary; |
| 514 | ptrdiff_t next_boundary; | 514 | |
| 515 | { | 515 | scan = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, NULL, &scan_byte, 1); |
| 516 | ptrdiff_t opoint = PT, opoint_byte = PT_BYTE; | ||
| 517 | scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1); | ||
| 518 | scan = PT, scan_byte = PT_BYTE; | ||
| 519 | SET_PT_BOTH (opoint, opoint_byte); | ||
| 520 | next_boundary = scan; | 516 | next_boundary = scan; |
| 521 | } | ||
| 522 | 517 | ||
| 523 | window = Fget_buffer_window (Fcurrent_buffer (), Qnil); | 518 | window = Fget_buffer_window (Fcurrent_buffer (), Qnil); |
| 524 | w = ! NILP (window) ? XWINDOW (window) : NULL; | 519 | w = ! NILP (window) ? XWINDOW (window) : NULL; |
| @@ -835,14 +830,10 @@ This is the horizontal position of the character | |||
| 835 | following any initial whitespace. */) | 830 | following any initial whitespace. */) |
| 836 | (void) | 831 | (void) |
| 837 | { | 832 | { |
| 838 | Lisp_Object val; | 833 | ptrdiff_t posbyte; |
| 839 | ptrdiff_t opoint = PT, opoint_byte = PT_BYTE; | ||
| 840 | |||
| 841 | scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, 1); | ||
| 842 | 834 | ||
| 843 | XSETFASTINT (val, position_indentation (PT_BYTE)); | 835 | find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, NULL, &posbyte, 1); |
| 844 | SET_PT_BOTH (opoint, opoint_byte); | 836 | return make_number (position_indentation (posbyte)); |
| 845 | return val; | ||
| 846 | } | 837 | } |
| 847 | 838 | ||
| 848 | static ptrdiff_t | 839 | static ptrdiff_t |
| @@ -935,16 +926,13 @@ position_indentation (ptrdiff_t pos_byte) | |||
| 935 | bool | 926 | bool |
| 936 | indented_beyond_p (ptrdiff_t pos, ptrdiff_t pos_byte, EMACS_INT column) | 927 | indented_beyond_p (ptrdiff_t pos, ptrdiff_t pos_byte, EMACS_INT column) |
| 937 | { | 928 | { |
| 938 | ptrdiff_t val; | 929 | while (pos > BEGV && FETCH_BYTE (pos_byte) == '\n') |
| 939 | ptrdiff_t opoint = PT, opoint_byte = PT_BYTE; | 930 | { |
| 940 | 931 | DEC_BOTH (pos, pos_byte); | |
| 941 | SET_PT_BOTH (pos, pos_byte); | 932 | pos = find_newline (pos, pos_byte, BEGV, BEGV_BYTE, |
| 942 | while (PT > BEGV && FETCH_BYTE (PT_BYTE) == '\n') | 933 | -1, NULL, &pos_byte, 0); |
| 943 | scan_newline (PT - 1, PT_BYTE - 1, BEGV, BEGV_BYTE, -1, 0); | 934 | } |
| 944 | 935 | return position_indentation (pos_byte) >= column; | |
| 945 | val = position_indentation (PT_BYTE); | ||
| 946 | SET_PT_BOTH (opoint, opoint_byte); | ||
| 947 | return val >= column; | ||
| 948 | } | 936 | } |
| 949 | 937 | ||
| 950 | DEFUN ("move-to-column", Fmove_to_column, Smove_to_column, 1, 2, | 938 | DEFUN ("move-to-column", Fmove_to_column, Smove_to_column, 1, 2, |
diff --git a/src/lisp.h b/src/lisp.h index 3dab0d6ddfd..f3a78f48a17 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3834,8 +3834,8 @@ extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t, | |||
| 3834 | ptrdiff_t, ptrdiff_t, Lisp_Object); | 3834 | ptrdiff_t, ptrdiff_t, Lisp_Object); |
| 3835 | extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, | 3835 | extern ptrdiff_t find_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, |
| 3836 | ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool); | 3836 | ptrdiff_t, ptrdiff_t *, ptrdiff_t *, bool); |
| 3837 | extern EMACS_INT scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, | 3837 | extern ptrdiff_t scan_newline (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, |
| 3838 | EMACS_INT, bool); | 3838 | ptrdiff_t, bool); |
| 3839 | extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t, | 3839 | extern ptrdiff_t find_newline_no_quit (ptrdiff_t, ptrdiff_t, |
| 3840 | ptrdiff_t, ptrdiff_t *); | 3840 | ptrdiff_t, ptrdiff_t *); |
| 3841 | extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t, | 3841 | extern ptrdiff_t find_before_next_newline (ptrdiff_t, ptrdiff_t, |
diff --git a/src/search.c b/src/search.c index 761c12a364a..99e8d2501fe 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -859,88 +859,20 @@ find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 859 | If ALLOW_QUIT, set immediate_quit. That's good to do | 859 | If ALLOW_QUIT, set immediate_quit. That's good to do |
| 860 | except in special cases. */ | 860 | except in special cases. */ |
| 861 | 861 | ||
| 862 | EMACS_INT | 862 | ptrdiff_t |
| 863 | scan_newline (ptrdiff_t start, ptrdiff_t start_byte, | 863 | scan_newline (ptrdiff_t start, ptrdiff_t start_byte, |
| 864 | ptrdiff_t limit, ptrdiff_t limit_byte, | 864 | ptrdiff_t limit, ptrdiff_t limit_byte, |
| 865 | EMACS_INT count, bool allow_quit) | 865 | ptrdiff_t count, bool allow_quit) |
| 866 | { | 866 | { |
| 867 | int direction = ((count > 0) ? 1 : -1); | 867 | ptrdiff_t charpos, bytepos, shortage; |
| 868 | |||
| 869 | unsigned char *cursor; | ||
| 870 | unsigned char *base; | ||
| 871 | |||
| 872 | ptrdiff_t ceiling; | ||
| 873 | unsigned char *ceiling_addr; | ||
| 874 | |||
| 875 | bool old_immediate_quit = immediate_quit; | ||
| 876 | |||
| 877 | if (allow_quit) | ||
| 878 | immediate_quit++; | ||
| 879 | 868 | ||
| 880 | if (count > 0) | 869 | charpos = find_newline (start, start_byte, limit, limit_byte, |
| 881 | { | 870 | count, &shortage, &bytepos, allow_quit); |
| 882 | while (start_byte < limit_byte) | 871 | if (shortage) |
| 883 | { | 872 | TEMP_SET_PT_BOTH (limit, limit_byte); |
| 884 | ceiling = BUFFER_CEILING_OF (start_byte); | ||
| 885 | ceiling = min (limit_byte - 1, ceiling); | ||
| 886 | ceiling_addr = BYTE_POS_ADDR (ceiling) + 1; | ||
| 887 | base = (cursor = BYTE_POS_ADDR (start_byte)); | ||
| 888 | |||
| 889 | do | ||
| 890 | { | ||
| 891 | unsigned char *nl = memchr (cursor, '\n', ceiling_addr - cursor); | ||
| 892 | if (! nl) | ||
| 893 | break; | ||
| 894 | if (--count == 0) | ||
| 895 | { | ||
| 896 | immediate_quit = old_immediate_quit; | ||
| 897 | start_byte += nl - base + 1; | ||
| 898 | start = BYTE_TO_CHAR (start_byte); | ||
| 899 | TEMP_SET_PT_BOTH (start, start_byte); | ||
| 900 | return 0; | ||
| 901 | } | ||
| 902 | cursor = nl + 1; | ||
| 903 | } | ||
| 904 | while (cursor < ceiling_addr); | ||
| 905 | |||
| 906 | start_byte += ceiling_addr - base; | ||
| 907 | } | ||
| 908 | } | ||
| 909 | else | 873 | else |
| 910 | { | 874 | TEMP_SET_PT_BOTH (charpos, bytepos); |
| 911 | while (start_byte > limit_byte) | 875 | return shortage; |
| 912 | { | ||
| 913 | ceiling = BUFFER_FLOOR_OF (start_byte - 1); | ||
| 914 | ceiling = max (limit_byte, ceiling); | ||
| 915 | ceiling_addr = BYTE_POS_ADDR (ceiling); | ||
| 916 | base = (cursor = BYTE_POS_ADDR (start_byte - 1) + 1); | ||
| 917 | while (1) | ||
| 918 | { | ||
| 919 | unsigned char *nl = memrchr (ceiling_addr, '\n', | ||
| 920 | cursor - ceiling_addr); | ||
| 921 | if (! nl) | ||
| 922 | break; | ||
| 923 | |||
| 924 | if (++count == 0) | ||
| 925 | { | ||
| 926 | immediate_quit = old_immediate_quit; | ||
| 927 | /* Return the position AFTER the match we found. */ | ||
| 928 | start_byte += nl - base + 1; | ||
| 929 | start = BYTE_TO_CHAR (start_byte); | ||
| 930 | TEMP_SET_PT_BOTH (start, start_byte); | ||
| 931 | return 0; | ||
| 932 | } | ||
| 933 | |||
| 934 | cursor = nl; | ||
| 935 | } | ||
| 936 | start_byte += ceiling_addr - base; | ||
| 937 | } | ||
| 938 | } | ||
| 939 | |||
| 940 | TEMP_SET_PT_BOTH (limit, limit_byte); | ||
| 941 | immediate_quit = old_immediate_quit; | ||
| 942 | |||
| 943 | return count * direction; | ||
| 944 | } | 876 | } |
| 945 | 877 | ||
| 946 | /* Like find_newline, but doesn't allow QUITting and doesn't return | 878 | /* Like find_newline, but doesn't allow QUITting and doesn't return |