APPROVE COMMIT
NOTE: This patch has been committed
# HG changeset patch
# User Aidan Kehoe <kehoea(a)parhasard.net>
# Date 1537213835 -3600
# Mon Sep 17 20:50:35 2018 +0100
# Node ID 073c3792b109212ab00875dba328668d20436e40
# Parent b6e0eddc51b9cced629afa296a5806555b76458f
Further reduce calls to charbpos_to_bytebpos(), editfns.c
src/ChangeLog addition:
2018-09-17 Aidan Kehoe <kehoea(a)parhasard.net>
* editfns.c (byte_beginning_of_line_p): New. Byte-oriented
equivalent of beginning_of_line_p().
* editfns.c (Ffollowing_char):
* editfns.c (Fpreceding_char):
* editfns.c (Fbobp):
* editfns.c (Feobp):
* editfns.c (Fbolp):
* editfns.c (Feolp):
* editfns.c (Fchar_after):
* editfns.c (Fchar_before):
Reduce calls to charbpos_to_bytebpos() in all these functions,
which a) will lead to fewer O(N) operations (often zero O(N)
operations) for a certain (rare) pattern of calls, and b)
eliminates the C function overhead all the time, which is of value
in itself, in these functions with byte codes.
* lisp.h:
Revise the declaration of beginning_of_line_p() to return a
Boolint.
diff -r b6e0eddc51b9 -r 073c3792b109 src/ChangeLog
--- a/src/ChangeLog Sun Sep 16 23:10:14 2018 +0100
+++ b/src/ChangeLog Mon Sep 17 20:50:35 2018 +0100
@@ -1,3 +1,24 @@
+2018-09-17 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ * editfns.c (byte_beginning_of_line_p): New. Byte-oriented
+ equivalent of beginning_of_line_p().
+ * editfns.c (Ffollowing_char):
+ * editfns.c (Fpreceding_char):
+ * editfns.c (Fbobp):
+ * editfns.c (Feobp):
+ * editfns.c (Fbolp):
+ * editfns.c (Feolp):
+ * editfns.c (Fchar_after):
+ * editfns.c (Fchar_before):
+ Reduce calls to charbpos_to_bytebpos() in all these functions,
+ which a) will lead to fewer O(N) operations (often zero O(N)
+ operations) for a certain (rare) pattern of calls, and b)
+ eliminates the C function overhead all the time, which is of value
+ in itself, in these functions with byte codes.
+ * lisp.h:
+ Revise the declaration of beginning_of_line_p() to return a
+ Boolint.
+
2018-08-26 Aidan Kehoe <kehoea(a)parhasard.net>
* bytecode.c:
diff -r b6e0eddc51b9 -r 073c3792b109 src/editfns.c
--- a/src/editfns.c Sun Sep 16 23:10:14 2018 +0100
+++ b/src/editfns.c Mon Sep 17 20:50:35 2018 +0100
@@ -468,10 +468,10 @@
(buffer))
{
struct buffer *b = decode_buffer (buffer, 1);
- if (BUF_PT (b) >= BUF_ZV (b))
+ if (BYTE_BUF_PT (b) >= BYTE_BUF_ZV (b))
return Qzero; /* #### Gag me! */
else
- return make_char (BUF_FETCH_CHAR (b, BUF_PT (b)));
+ return make_char (BYTE_BUF_FETCH_CHAR (b, BYTE_BUF_PT (b)));
}
DEFUN ("preceding-char", Fpreceding_char, 0, 1, 0, /*
@@ -482,10 +482,15 @@
(buffer))
{
struct buffer *b = decode_buffer (buffer, 1);
- if (BUF_PT (b) <= BUF_BEGV (b))
+ if (BYTE_BUF_PT (b) <= BYTE_BUF_BEGV (b))
return Qzero; /* #### Gag me! */
else
- return make_char (BUF_FETCH_CHAR (b, BUF_PT (b) - 1));
+ {
+ Bytebpos bpos = BYTE_BUF_PT (b);
+ DEC_BYTEBPOS (b, bpos);
+
+ return make_char (BYTE_BUF_FETCH_CHAR (b, bpos));
+ }
}
DEFUN ("bobp", Fbobp, 0, 1, 0, /*
@@ -496,7 +501,7 @@
(buffer))
{
struct buffer *b = decode_buffer (buffer, 1);
- return BUF_PT (b) == BUF_BEGV (b) ? Qt : Qnil;
+ return BYTE_BUF_PT (b) == BYTE_BUF_BEGV (b) ? Qt : Qnil;
}
DEFUN ("eobp", Feobp, 0, 1, 0, /*
@@ -507,16 +512,29 @@
(buffer))
{
struct buffer *b = decode_buffer (buffer, 1);
- return BUF_PT (b) == BUF_ZV (b) ? Qt : Qnil;
+ return BYTE_BUF_PT (b) == BYTE_BUF_ZV (b) ? Qt : Qnil;
}
-int
+static Boolint
+byte_beginning_of_line_p (struct buffer *b, Bytebpos bpt)
+{
+ if (bpt <= BYTE_BUF_BEGV (b))
+ {
+ return 1;
+ }
+
+ DEC_BYTEBPOS (b, bpt);
+ return BYTE_BUF_FETCH_CHAR (b, bpt) == '\n';
+}
+
+/* #### Rework redisplay.c and the window code to use
+ byte_beginning_of_line_p() instead of this! */
+Boolint
beginning_of_line_p (struct buffer *b, Charbpos pt)
{
return pt <= BUF_BEGV (b) || BUF_FETCH_CHAR (b, pt - 1) == '\n';
}
-
DEFUN ("bolp", Fbolp, 0, 1, 0, /*
Return t if point is at the beginning of a line.
If BUFFER is nil, the current buffer is assumed.
@@ -524,7 +542,7 @@
(buffer))
{
struct buffer *b = decode_buffer (buffer, 1);
- return beginning_of_line_p (b, BUF_PT (b)) ? Qt : Qnil;
+ return byte_beginning_of_line_p (b, BYTE_BUF_PT (b)) ? Qt : Qnil;
}
DEFUN ("eolp", Feolp, 0, 1, 0, /*
@@ -535,7 +553,8 @@
(buffer))
{
struct buffer *b = decode_buffer (buffer, 1);
- return (BUF_PT (b) == BUF_ZV (b) || BUF_FETCH_CHAR (b, BUF_PT (b)) == '\n')
+ return (BYTE_BUF_PT (b) == BYTE_BUF_ZV (b) ||
+ BYTE_BUF_FETCH_CHAR (b, BYTE_BUF_PT (b)) == '\n')
? Qt : Qnil;
}
@@ -549,12 +568,12 @@
(pos, buffer))
{
struct buffer *b = decode_buffer (buffer, 1);
- Charbpos n = (NILP (pos) ? BUF_PT (b) :
- get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD));
+ Bytebpos bn = (NILP (pos) ? BYTE_BUF_PT (b) :
+ get_buffer_pos_byte (b, pos, GB_NO_ERROR_IF_BAD));
- if (n < 0 || n == BUF_ZV (b))
+ if (bn < 0 || bn == BYTE_BUF_ZV (b))
return Qnil;
- return make_char (BUF_FETCH_CHAR (b, n));
+ return make_char (BYTE_BUF_FETCH_CHAR (b, bn));
}
DEFUN ("char-before", Fchar_before, 0, 2, 0, /*
@@ -567,14 +586,15 @@
(pos, buffer))
{
struct buffer *b = decode_buffer (buffer, 1);
- Charbpos n = (NILP (pos) ? BUF_PT (b) :
- get_buffer_pos_char (b, pos, GB_NO_ERROR_IF_BAD));
+ Bytebpos bn = (NILP (pos) ? BYTE_BUF_PT (b) :
+ get_buffer_pos_byte (b, pos, GB_NO_ERROR_IF_BAD));
- n--;
+ if (bn <= BYTE_BUF_BEGV (b))
+ return Qnil;
- if (n < BUF_BEGV (b))
- return Qnil;
- return make_char (BUF_FETCH_CHAR (b, n));
+ DEC_BYTEBPOS (b, bn);
+
+ return make_char (BYTE_BUF_FETCH_CHAR (b, bn));
}
diff -r b6e0eddc51b9 -r 073c3792b109 src/lisp.h
--- a/src/lisp.h Sun Sep 16 23:10:14 2018 +0100
+++ b/src/lisp.h Mon Sep 17 20:50:35 2018 +0100
@@ -4835,7 +4835,7 @@
Lisp_Object save_excursion_restore (Lisp_Object);
Lisp_Object save_restriction_restore (Lisp_Object);
void widen_buffer (struct buffer *b, int no_clip);
-int beginning_of_line_p (struct buffer *b, Charbpos pt);
+Boolint beginning_of_line_p (struct buffer *, Charbpos);
Lisp_Object save_current_buffer_restore (Lisp_Object);
extern Lisp_Object Qformat;
--
‘As I sat looking up at the Guinness ad, I could never figure out /
How your man stayed up on the surfboard after forty pints of stout’
(C. Moore)