Commit 657924ff authored by Dmitry Antipov's avatar Dmitry Antipov

Introduce fast path for the widely used marker operation.

* alloc.c (build_marker): New function.
* lisp.h (build_marker): New prototype.
* buffer.c (clone_per_buffer_values, Fmake_indirect_buffer): Use it.
* composite.c (autocmp_chars): Likewise.
* editfns.c (buildmark): Remove.
(Fpoint_marker, Fpoint_min_marker, Fpoint_max_marker)
(save_restriction_save): Use build_marker.
* marker.c (buf_charpos_to_bytepos, buf_bytepos_to_charpos): Likewise.
* window.c (save_window_save): Likewise.
parent 6edc3d28
2012-07-06 Dmitry Antipov <dmantipov@yandex.ru>
Introduce fast path for the widely used marker operation.
* alloc.c (build_marker): New function.
* lisp.h (build_marker): New prototype.
* buffer.c (clone_per_buffer_values, Fmake_indirect_buffer): Use it.
* composite.c (autocmp_chars): Likewise.
* editfns.c (buildmark): Remove.
(Fpoint_marker, Fpoint_min_marker, Fpoint_max_marker)
(save_restriction_save): Use build_marker.
* marker.c (buf_charpos_to_bytepos, buf_bytepos_to_charpos): Likewise.
* window.c (save_window_save): Likewise.
2012-07-06 Dmitry Antipov <dmantipov@yandex.ru>
Do not use Fdelete_overlay in delete_all_overlays
......
......@@ -3641,6 +3641,33 @@ DEFUN ("make-marker", Fmake_marker, Smake_marker, 0, 0, 0,
return val;
}
/* Return a newly allocated marker which points into BUF
at character position CHARPOS and byte position BYTEPOS. */
Lisp_Object
build_marker (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t bytepos)
{
Lisp_Object obj;
struct Lisp_Marker *m;
/* No dead buffers here. */
eassert (!NILP (BVAR (buf, name)));
/* Every character is at least one byte. */
eassert (charpos <= bytepos);
obj = allocate_misc ();
XMISCTYPE (obj) = Lisp_Misc_Marker;
m = XMARKER (obj);
m->buffer = buf;
m->charpos = charpos;
m->bytepos = bytepos;
m->insertion_type = 0;
m->next = BUF_MARKERS (buf);
BUF_MARKERS (buf) = m;
return obj;
}
/* Put MARKER back on the free list after using it temporarily. */
void
......
......@@ -458,11 +458,8 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
static void
clone_per_buffer_values (struct buffer *from, struct buffer *to)
{
Lisp_Object to_buffer;
int offset;
XSETBUFFER (to_buffer, to);
for_each_per_buffer_object_at (offset)
{
Lisp_Object obj;
......@@ -475,9 +472,9 @@ clone_per_buffer_values (struct buffer *from, struct buffer *to)
if (MARKERP (obj) && XMARKER (obj)->buffer == from)
{
struct Lisp_Marker *m = XMARKER (obj);
obj = Fmake_marker ();
obj = build_marker (to, m->charpos, m->bytepos);
XMARKER (obj)->insertion_type = m->insertion_type;
set_marker_both (obj, to_buffer, m->charpos, m->bytepos);
}
PER_BUFFER_VALUE (to, offset) = obj;
......@@ -615,32 +612,24 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
eassert (NILP (BVAR (b->base_buffer, begv_marker)));
eassert (NILP (BVAR (b->base_buffer, zv_marker)));
BVAR (b->base_buffer, pt_marker) = Fmake_marker ();
set_marker_both (BVAR (b->base_buffer, pt_marker), base_buffer,
b->base_buffer->pt,
b->base_buffer->pt_byte);
BVAR (b->base_buffer, pt_marker)
= build_marker (b->base_buffer, b->base_buffer->pt, b->base_buffer->pt_byte);
BVAR (b->base_buffer, begv_marker)
= build_marker (b->base_buffer, b->base_buffer->begv, b->base_buffer->begv_byte);
BVAR (b->base_buffer, begv_marker) = Fmake_marker ();
set_marker_both (BVAR (b->base_buffer, begv_marker), base_buffer,
b->base_buffer->begv,
b->base_buffer->begv_byte);
BVAR (b->base_buffer, zv_marker)
= build_marker (b->base_buffer, b->base_buffer->zv, b->base_buffer->zv_byte);
BVAR (b->base_buffer, zv_marker) = Fmake_marker ();
set_marker_both (BVAR (b->base_buffer, zv_marker), base_buffer,
b->base_buffer->zv,
b->base_buffer->zv_byte);
XMARKER (BVAR (b->base_buffer, zv_marker))->insertion_type = 1;
}
if (NILP (clone))
{
/* Give the indirect buffer markers for its narrowing. */
BVAR (b, pt_marker) = Fmake_marker ();
set_marker_both (BVAR (b, pt_marker), buf, b->pt, b->pt_byte);
BVAR (b, begv_marker) = Fmake_marker ();
set_marker_both (BVAR (b, begv_marker), buf, b->begv, b->begv_byte);
BVAR (b, zv_marker) = Fmake_marker ();
set_marker_both (BVAR (b, zv_marker), buf, b->zv, b->zv_byte);
BVAR (b, pt_marker) = build_marker (b, b->pt, b->pt_byte);
BVAR (b, begv_marker) = build_marker (b, b->begv, b->begv_byte);
BVAR (b, zv_marker) = build_marker (b, b->zv, b->zv_byte);
XMARKER (BVAR (b, zv_marker))->insertion_type = 1;
}
else
......
......@@ -951,11 +951,8 @@ autocmp_chars (Lisp_Object rule, ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t
/* Save point as marker before calling out to lisp. */
if (NILP (string))
{
Lisp_Object m = Fmake_marker ();
set_marker_both (m, Qnil, pt, pt_byte);
record_unwind_protect (restore_point_unwind, m);
}
record_unwind_protect (restore_point_unwind,
build_marker (current_buffer, pt, pt_byte));
args[0] = Vauto_composition_function;
args[1] = AREF (rule, 2);
......
......@@ -205,15 +205,6 @@ DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0,
XSETFASTINT (val, 0);
return val;
}
static Lisp_Object
buildmark (ptrdiff_t charpos, ptrdiff_t bytepos)
{
register Lisp_Object mark;
mark = Fmake_marker ();
set_marker_both (mark, Qnil, charpos, bytepos);
return mark;
}
DEFUN ("point", Fpoint, Spoint, 0, 0, 0,
doc: /* Return value of point, as an integer.
......@@ -229,7 +220,7 @@ DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0,
doc: /* Return value of point, as a marker object. */)
(void)
{
return buildmark (PT, PT_BYTE);
return build_marker (current_buffer, PT, PT_BYTE);
}
DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ",
......@@ -1003,7 +994,7 @@ DEFUN ("point-min-marker", Fpoint_min_marker, Spoint_min_marker, 0, 0, 0,
This is the beginning, unless narrowing (a buffer restriction) is in effect. */)
(void)
{
return buildmark (BEGV, BEGV_BYTE);
return build_marker (current_buffer, BEGV, BEGV_BYTE);
}
DEFUN ("point-max", Fpoint_max, Spoint_max, 0, 0, 0,
......@@ -1023,7 +1014,7 @@ This is (1+ (buffer-size)), unless narrowing (a buffer restriction)
is in effect, in which case it is less. */)
(void)
{
return buildmark (ZV, ZV_BYTE);
return build_marker (current_buffer, ZV, ZV_BYTE);
}
DEFUN ("gap-position", Fgap_position, Sgap_position, 0, 0, 0,
......@@ -3289,8 +3280,8 @@ save_restriction_save (void)
{
Lisp_Object beg, end;
beg = buildmark (BEGV, BEGV_BYTE);
end = buildmark (ZV, ZV_BYTE);
beg = build_marker (current_buffer, BEGV, BEGV_BYTE);
end = build_marker (current_buffer, ZV, ZV_BYTE);
/* END must move forward if text is inserted at its exact location. */
XMARKER (end)->insertion_type = 1;
......
......@@ -2853,6 +2853,7 @@ extern Lisp_Object set_marker_restricted (Lisp_Object, Lisp_Object, Lisp_Object)
extern Lisp_Object set_marker_both (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
extern Lisp_Object set_marker_restricted_both (Lisp_Object, Lisp_Object,
ptrdiff_t, ptrdiff_t);
extern Lisp_Object build_marker (struct buffer *, ptrdiff_t, ptrdiff_t);
extern void syms_of_marker (void);
/* Defined in fileio.c */
......
......@@ -187,12 +187,7 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
cache the correspondence by creating a marker here.
It will last until the next GC. */
if (record)
{
Lisp_Object marker, buffer;
marker = Fmake_marker ();
XSETBUFFER (buffer, b);
set_marker_both (marker, buffer, best_below, best_below_byte);
}
build_marker (b, best_below, best_below_byte);
if (byte_debug_flag)
byte_char_debug_check (b, charpos, best_below_byte);
......@@ -218,12 +213,7 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
cache the correspondence by creating a marker here.
It will last until the next GC. */
if (record)
{
Lisp_Object marker, buffer;
marker = Fmake_marker ();
XSETBUFFER (buffer, b);
set_marker_both (marker, buffer, best_above, best_above_byte);
}
build_marker (b, best_above, best_above_byte);
if (byte_debug_flag)
byte_char_debug_check (b, charpos, best_above_byte);
......@@ -365,12 +355,7 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
But don't do it if BUF_MARKERS is nil;
that is a signal from Fset_buffer_multibyte. */
if (record && BUF_MARKERS (b))
{
Lisp_Object marker, buffer;
marker = Fmake_marker ();
XSETBUFFER (buffer, b);
set_marker_both (marker, buffer, best_below, best_below_byte);
}
build_marker (b, best_below, best_below_byte);
if (byte_debug_flag)
byte_char_debug_check (b, best_below, bytepos);
......@@ -398,12 +383,7 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
But don't do it if BUF_MARKERS is nil;
that is a signal from Fset_buffer_multibyte. */
if (record && BUF_MARKERS (b))
{
Lisp_Object marker, buffer;
marker = Fmake_marker ();
XSETBUFFER (buffer, b);
set_marker_both (marker, buffer, best_above, best_above_byte);
}
build_marker (b, best_above, best_above_byte);
if (byte_debug_flag)
byte_char_debug_check (b, best_above, bytepos);
......
......@@ -5911,12 +5911,9 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
is the selected window, then get the value of point from
the buffer; pointm is garbage in the selected window. */
if (EQ (window, selected_window))
{
p->pointm = Fmake_marker ();
set_marker_both (p->pointm, w->buffer,
BUF_PT (XBUFFER (w->buffer)),
BUF_PT_BYTE (XBUFFER (w->buffer)));
}
p->pointm = build_marker (XBUFFER (w->buffer),
BUF_PT (XBUFFER (w->buffer)),
BUF_PT_BYTE (XBUFFER (w->buffer)));
else
p->pointm = Fcopy_marker (w->pointm, Qnil);
XMARKER (p->pointm)->insertion_type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment