* 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>
+
+ 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
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
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;
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;
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
/* 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);
XSETFASTINT (val, 0);
return val;
}
-\f
-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.
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: ",
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,
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,
{
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;
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 */
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);
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);
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);
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);
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