Mercurial > hg > xemacs-beta
changeset 4844:91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
dynarr.c: Add comment explaining Dynarr_largest() use.
dynarr.c: In Dynarr_insert_many(), don't call Dynarr_resize() unless we
actually need to resize, and note that an assert() that we are
inserting at or below the current end could be wrong if code
wants to access stuff between `len' and `largest'.
dynarr.c: Don't just Dynarr_resize() to the right size; instead use
Dynarr_reset() then Dynarr_add_many(), so that the 'len' and
'largest' and such get set properly.
dynarr.c, faces.c, gutter.c, lisp.h, lread.c, lrecord.h, redisplay-output.c, redisplay.c: Rename Dynarr member 'cur' to 'len' since it's the length of
the dynarr, not really a pointer to a "current insertion point".
Use type_checking_assert() instead of just assert() in some places.
Add additional assertions (Dynarr_verify*()) to check that we're
being given positions within range. Use them in Dynarr_at,
Dynarr_atp, etc. New Dynarr_atp_allow_end() for retrieving a
pointer to a position that might be the element past the last one.
New Dynarr_past_lastp() to retrieve a pointer to the position
past the last one, using Dynarr_atp_allow_end(). Change code
appropriately to use it.
Rename Dynarr_end() to Dynarr_lastp() (pointer to the last
element) for clarity, and change code appropriately to use it.
Change code appropriately to use Dynarr_begin().
Rewrite Dynarr_add_many(). New version can accept a NULL pointer
to mean "reserve space but don't put anything in it". Used by
stack_like_malloc().
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 13 Jan 2010 04:07:42 -0600 |
parents | 715b15990d0a |
children | a3c673c0720b |
files | src/ChangeLog src/dynarr.c src/faces.c src/gutter.c src/lisp.h src/lread.c src/lrecord.h src/redisplay-output.c src/redisplay.c |
diffstat | 9 files changed, 271 insertions(+), 93 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Wed Jan 13 03:01:43 2010 -0600 +++ b/src/ChangeLog Wed Jan 13 04:07:42 2010 -0600 @@ -1,3 +1,73 @@ +2010-01-13 Ben Wing <ben@xemacs.org> + + * dynarr.c: + Add comment explaining Dynarr_largest() use. + + * dynarr.c (Dynarr_insert_many): + In Dynarr_insert_many(), don't call Dynarr_resize() unless we + actually need to resize, and note that an assert() that we are + inserting at or below the current end could be wrong if code + wants to access stuff between `len' and `largest'. + + * dynarr.c (stack_like_malloc): + Don't just Dynarr_resize() to the right size; instead use + Dynarr_reset() then Dynarr_add_many(), so that the 'len' and + 'largest' and such get set properly. + + * dynarr.c (Dynarr_insert_many): + * dynarr.c (Dynarr_delete_many): + * dynarr.c (Dynarr_memory_usage): + * dynarr.c (stack_like_free): + * faces.c (add_face_cachel): + * gutter.c (output_gutter): + * lisp.h: + * lisp.h (Dynarr_declare): + * lisp.h (Dynarr_length): + * lisp.h (Dynarr_add): + * lisp.h (Dynarr_increment): + * lisp.h (Dynarr_pop): + * lread.c (define_structure_type): + * lread.c (define_structure_type_keyword): + * lrecord.h: + * lrecord.h (XD_DYNARR_DESC): + * lrecord.h (XD_LISP_DYNARR_DESC): + * redisplay-output.c (compare_display_blocks): + * redisplay-output.c (output_display_line): + * redisplay.c (add_ichar_rune_1): + * redisplay.c (create_text_block): + * redisplay.c (generate_formatted_string_db): + * redisplay.c (create_string_text_block): + * redisplay.c (point_visible): + * redisplay.c (mark_glyph_block_dynarr): + * redisplay.c (mark_redisplay_structs): + * redisplay.c (line_start_cache_end): + * redisplay.c (update_line_start_cache): + * redisplay.c (glyph_to_pixel_translation): + * redisplay.c (pixel_to_glyph_translation): + Rename Dynarr member 'cur' to 'len' since it's the length of + the dynarr, not really a pointer to a "current insertion point". + + Use type_checking_assert() instead of just assert() in some places. + + + Add additional assertions (Dynarr_verify*()) to check that we're + being given positions within range. Use them in Dynarr_at, + Dynarr_atp, etc. New Dynarr_atp_allow_end() for retrieving a + pointer to a position that might be the element past the last one. + New Dynarr_past_lastp() to retrieve a pointer to the position + past the last one, using Dynarr_atp_allow_end(). Change code + appropriately to use it. + + Rename Dynarr_end() to Dynarr_lastp() (pointer to the last + element) for clarity, and change code appropriately to use it. + + Change code appropriately to use Dynarr_begin(). + + Rewrite Dynarr_add_many(). New version can accept a NULL pointer + to mean "reserve space but don't put anything in it". Used by + stack_like_malloc(). + + 2010-01-13 Ben Wing <ben@xemacs.org> * lisp.h:
--- a/src/dynarr.c Wed Jan 13 03:01:43 2010 -0600 +++ b/src/dynarr.c Wed Jan 13 04:07:42 2010 -0600 @@ -1,6 +1,6 @@ /* Support for dynamic arrays. Copyright (C) 1993 Sun Microsystems, Inc. - Copyright (C) 2002, 2003, 2004 Ben Wing. + Copyright (C) 2002, 2003, 2004, 2005 Ben Wing. This file is part of XEmacs. @@ -98,7 +98,8 @@ int Dynarr_largest(d) [MACRO] Return the maximum value that Dynarr_length(d) would - ever have returned. + ever have returned. This is used esp. in the redisplay code, + which reuses dynarrs for performance reasons. type Dynarr_at(d, i) [MACRO] Return the element at the specified index (no bounds checking @@ -217,30 +218,33 @@ { Dynarr *dy = (Dynarr *) Dynarr_verify (d); - Dynarr_resize (dy, dy->cur+len); + if (dy->len + len > dy->max) + Dynarr_resize (dy, dy->len + len); #if 0 /* WTF? We should be catching these problems. */ /* Silently adjust start to be valid. */ - if (start > dy->cur) - start = dy->cur; + if (start > dy->len) + start = dy->len; else if (start < 0) start = 0; #else - assert (start >= 0 && start <= dy->cur); + /* #### This could conceivably be wrong, if code wants to access stuff + between len and largest. */ + type_checking_assert (start >= 0 && start <= dy->len); #endif - if (start != dy->cur) + if (start != dy->len) { memmove ((char *) dy->base + (start + len)*dy->elsize, (char *) dy->base + start*dy->elsize, - (dy->cur - start)*dy->elsize); + (dy->len - start)*dy->elsize); } if (el) memcpy ((char *) dy->base + start*dy->elsize, el, len*dy->elsize); - dy->cur += len; + dy->len += len; - if (dy->cur > dy->largest) - dy->largest = dy->cur; + if (dy->len > dy->largest) + dy->largest = dy->len; } void @@ -248,11 +252,11 @@ { Dynarr *dy = (Dynarr *) Dynarr_verify (d); - assert (start >= 0 && len >= 0 && start + len <= dy->cur); + type_checking_assert (start >= 0 && len >= 0 && start + len <= dy->len); memmove ((char *) dy->base + start*dy->elsize, (char *) dy->base + (start + len)*dy->elsize, - (dy->cur - start - len)*dy->elsize); - dy->cur -= len; + (dy->len - start - len)*dy->elsize); + dy->len -= len; } void @@ -304,7 +308,7 @@ Bytecount malloc_used = malloced_storage_size (dy->base, dy->elsize * dy->max, 0); /* #### This may or may not be correct. Some Dynarrs would - prefer that we use dy->cur instead of dy->largest here. */ + prefer that we use dy->len instead of dy->largest here. */ Bytecount was_requested = dy->elsize * dy->largest; Bytecount dynarr_overhead = dy->elsize * (dy->max - dy->largest); @@ -353,7 +357,8 @@ else this_one = Dynarr_new (char); Dynarr_add (stack_like_in_use_list, this_one); - Dynarr_resize (this_one, size); + Dynarr_reset (this_one); + Dynarr_add_many (this_one, 0, size); return Dynarr_atp (this_one, 0); }
--- a/src/faces.c Wed Jan 13 03:01:43 2010 -0600 +++ b/src/faces.c Wed Jan 13 04:07:42 2010 -0600 @@ -1361,8 +1361,7 @@ if (must_finish_frobbing) { int default_face = EQ (face, Vdefault_face); - struct face_cachel *cachel - = Dynarr_atp (w->face_cachels, Dynarr_length (w->face_cachels) - 1); + struct face_cachel *cachel = Dynarr_lastp (w->face_cachels); FROB (background_pixmap); MAYBE_UNFROB_BACKGROUND_PIXMAP;
--- a/src/gutter.c Wed Jan 13 03:01:43 2010 -0600 +++ b/src/gutter.c Wed Jan 13 04:07:42 2010 -0600 @@ -456,7 +456,7 @@ /* grab coordinates of last line and blank after it. */ if (Dynarr_length (ddla) > 0) { - dl = Dynarr_atp (ddla, Dynarr_length (ddla) - 1); + dl = Dynarr_lastp (ddla); ypos = dl->ypos + dl->descent - dl->clip; } else
--- a/src/lisp.h Wed Jan 13 03:01:43 2010 -0600 +++ b/src/lisp.h Wed Jan 13 04:07:42 2010 -0600 @@ -1713,7 +1713,7 @@ const struct lrecord_implementation *lisp_imp; \ int locked; \ int elsize; \ - int cur; \ + int len; \ int largest; \ int max #else @@ -1722,7 +1722,7 @@ type *base; \ const struct lrecord_implementation *lisp_imp; \ int elsize; \ - int cur; \ + int len; \ int largest; \ int max #endif /* ERROR_CHECK_STRUCTURES */ @@ -1733,7 +1733,7 @@ type *base; \ int locked; \ int elsize; \ - int cur; \ + int len; \ int largest; \ int max #else @@ -1741,7 +1741,7 @@ struct lrecord_header header; \ type *base; \ int elsize; \ - int cur; \ + int len; \ int largest; \ int max #endif /* ERROR_CHECK_STRUCTURES */ @@ -1754,10 +1754,85 @@ MODULE_API void *Dynarr_newf (int elsize); MODULE_API void Dynarr_resize (void *dy, Elemcount size); -MODULE_API void Dynarr_insert_many (void *d, const void *el, int len, int start); +MODULE_API void Dynarr_insert_many (void *d, const void *el, int len, + int start); MODULE_API void Dynarr_delete_many (void *d, int start, int len); MODULE_API void Dynarr_free (void *d); +#ifdef ERROR_CHECK_TYPES +DECLARE_INLINE_HEADER ( +int +Dynarr_verify_pos_at (void *d, int pos, const Ascbyte *file, int line) +) +{ + Dynarr *dy = (Dynarr *) d; + /* We use `largest', not `len', because the redisplay code often + accesses stuff between len and largest. */ + assert_at_line (pos >= 0 && pos < dy->largest, file, line); + return pos; +} +#else +#define Dynarr_verify_pos(d, pos, file, line) (pos) +#endif /* ERROR_CHECK_TYPES */ + +#ifdef ERROR_CHECK_TYPES +DECLARE_INLINE_HEADER ( +int +Dynarr_verify_pos_atp (void *d, int pos, const Ascbyte *file, int line) +) +{ + Dynarr *dy = (Dynarr *) d; + /* We use `largest', not `len', because the redisplay code often + accesses stuff between len and largest. */ + /* Code will often do something like ... + + val = make_bit_vector_from_byte_vector (Dynarr_atp (dyn, 0), + Dynarr_length (dyn)); + + which works fine when the Dynarr_length is non-zero, but when zero, + the result of Dynarr_atp() not only points past the end of the + allocated array, but the array may not have ever been allocated and + hence the return value is NULL. But the length of 0 causes the + pointer to never get checked. These can occur throughout the code + so we put in a special check. */ + if (pos == 0 && dy->len == 0) + return pos; + /* #### It's vaguely possible that some code could legitimately want to + retrieve a pointer to the position just past the end of dynarr memory. + This could happen with Dynarr_atp() but not Dynarr_at(). If so, it + will trigger this assert(). In such cases, it should be obvious that + the code wants to do this; rather than relaxing the assert, we should + probably create a new macro Dynarr_atp_allow_end() which is like + Dynarr_atp() but which allows for pointing at invalid addresses -- we + really want to check for cases of accessing just past the end of + memory, which is a likely off-by-one problem to occur and will usually + not trigger a protection fault (instead, you'll just get random + behavior, possibly overwriting other memory, which is bad). */ + assert_at_line (pos >= 0 && pos < dy->largest, file, line); + return pos; +} + +DECLARE_INLINE_HEADER ( +int +Dynarr_verify_pos_atp_allow_end (void *d, int pos, const Ascbyte *file, + int line) +) +{ + Dynarr *dy = (Dynarr *) d; + /* We use `largest', not `len', because the redisplay code often + accesses stuff between len and largest. + We also allow referencing the very end, past the end of allocated + legitimately space. See comments in Dynarr_verify_pos_atp.()*/ + assert_at_line (pos >= 0 && pos <= dy->largest, file, line); + return pos; +} + +#else +#define Dynarr_verify_pos_at(d, pos, file, line) (pos) +#define Dynarr_verify_pos_atp(d, pos, file, line) (pos) +#define Dynarr_verify_pos_atp_allow_end(d, pos, file, line) (pos) +#endif /* ERROR_CHECK_TYPES */ + #ifdef NEW_GC MODULE_API void *Dynarr_lisp_newf (int elsize, const struct lrecord_implementation @@ -1772,11 +1847,19 @@ #define Dynarr_new(type) ((type##_dynarr *) Dynarr_newf (sizeof (type))) #define Dynarr_new2(dynarr_type, type) \ ((dynarr_type *) Dynarr_newf (sizeof (type))) -#define Dynarr_at(d, pos) ((d)->base[pos]) -#define Dynarr_atp(d, pos) (&Dynarr_at (d, pos)) + +#define Dynarr_at(d, pos) \ + ((d)->base[Dynarr_verify_pos_at (d, pos, __FILE__, __LINE__)]) +#define Dynarr_atp_allow_end(d, pos) \ + (&((d)->base[Dynarr_verify_pos_atp_allow_end (d, pos, __FILE__, __LINE__)])) +#define Dynarr_atp(d, pos) \ + (&((d)->base[Dynarr_verify_pos_atp (d, pos, __FILE__, __LINE__)])) + +/* Old #define Dynarr_atp(d, pos) (&Dynarr_at (d, pos)) */ #define Dynarr_begin(d) Dynarr_atp (d, 0) -#define Dynarr_end(d) Dynarr_atp (d, Dynarr_length (d) - 1) -#define Dynarr_sizeof(d) ((d)->cur * (d)->elsize) +#define Dynarr_lastp(d) Dynarr_atp (d, Dynarr_length (d) - 1) +#define Dynarr_past_lastp(d) Dynarr_atp_allow_end (d, Dynarr_length (d)) +#define Dynarr_sizeof(d) ((d)->len * (d)->elsize) #ifdef ERROR_CHECK_STRUCTURES DECLARE_INLINE_HEADER ( @@ -1785,7 +1868,7 @@ ) { Dynarr *dy = (Dynarr *) d; - assert_at_line (dy->cur >= 0 && dy->cur <= dy->largest && + assert_at_line (dy->len >= 0 && dy->len <= dy->largest && dy->largest <= dy->max, file, line); return dy; } @@ -1797,7 +1880,7 @@ { Dynarr *dy = (Dynarr *) d; assert_at_line (!dy->locked, file, line); - assert_at_line (dy->cur >= 0 && dy->cur <= dy->largest && + assert_at_line (dy->len >= 0 && dy->len <= dy->largest && dy->largest <= dy->max, file, line); return dy; } @@ -1813,10 +1896,9 @@ #define Dynarr_unlock(d) #endif /* ERROR_CHECK_STRUCTURES */ -#define Dynarr_length(d) (Dynarr_verify (d)->cur) +#define Dynarr_length(d) (Dynarr_verify (d)->len) #define Dynarr_largest(d) (Dynarr_verify (d)->largest) -#define Dynarr_reset(d) (Dynarr_verify_mod (d)->cur = 0) -#define Dynarr_add_many(d, el, len) Dynarr_insert_many (d, el, len, (d)->cur) +#define Dynarr_reset(d) (Dynarr_verify_mod (d)->len = 0) #define Dynarr_insert_many_at_start(d, el, len) \ Dynarr_insert_many (d, el, len, 0) #define Dynarr_add_literal_string(d, s) Dynarr_add_many (d, s, sizeof (s) - 1) @@ -1836,35 +1918,63 @@ #define Dynarr_add(d, el) \ do { \ const struct lrecord_implementation *imp = (d)->lisp_imp; \ - if (Dynarr_verify_mod (d)->cur >= (d)->max) \ - Dynarr_resize ((d), (d)->cur+1); \ - ((d)->base)[(d)->cur] = (el); \ + if (Dynarr_verify_mod (d)->len >= (d)->max) \ + Dynarr_resize ((d), (d)->len+1); \ + ((d)->base)[(d)->len] = (el); \ \ if (imp) \ set_lheader_implementation \ - ((struct lrecord_header *)&(((d)->base)[(d)->cur]), imp); \ + ((struct lrecord_header *)&(((d)->base)[(d)->len]), imp); \ \ - (d)->cur++; \ - if ((d)->cur > (d)->largest) \ - (d)->largest = (d)->cur; \ + (d)->len++; \ + if ((d)->len > (d)->largest) \ + (d)->largest = (d)->len; \ } while (0) #else /* not NEW_GC */ #define Dynarr_add(d, el) ( \ - Dynarr_verify_mod (d)->cur >= (d)->max ? Dynarr_resize ((d), (d)->cur+1) : \ + Dynarr_verify_mod (d)->len >= (d)->max ? Dynarr_resize ((d), (d)->len+1) : \ (void) 0, \ - ((d)->base)[(d)->cur++] = (el), \ - (d)->cur > (d)->largest ? (d)->largest = (d)->cur : (int) 0) + ((d)->base)[(d)->len++] = (el), \ + (d)->len > (d)->largest ? (d)->largest = (d)->len : (int) 0) #endif /* not NEW_GC */ +/* Add LEN contiguous elements to a Dynarr */ + +DECLARE_INLINE_HEADER ( +void +Dynarr_add_many (void *d, const void *el, int len) +) +{ + /* This duplicates Dynarr_insert_many to some extent; but since it is + called so often, it seemed useful to remove the unnecessary stuff + from that function and to make it inline */ + Dynarr *dy = (Dynarr *) Dynarr_verify (d); + + if (dy->len + len > dy->max) + Dynarr_resize (dy, dy->len + len); + /* Some functions call us with a value of 0 to mean "reserve space but + don't write into it" */ + if (el) + memcpy ((char *) dy->base + dy->len*dy->elsize, el, len*dy->elsize); + dy->len += len; + + if (dy->len > dy->largest) + dy->largest = dy->len; +} /* The following defines will get you into real trouble if you aren't careful. But they can save a lot of execution time when used wisely. */ -#define Dynarr_increment(d) (Dynarr_verify_mod (d)->cur++) -#define Dynarr_set_size(d, n) (Dynarr_verify_mod (d)->cur = n) +#define Dynarr_increment(d) (Dynarr_verify_mod (d)->len++) +#define Dynarr_set_size(d, n) \ +do { \ + Bytecount _dss_n = (n); \ + structure_checking_assert (_dss_n >= 0 && _dss_n <= (d)->largest); \ + Dynarr_verify_mod (d)->len = _dss_n; \ +} while (0) #define Dynarr_pop(d) \ - (assert ((d)->cur > 0), Dynarr_verify_mod (d)->cur--, \ - Dynarr_at (d, (d)->cur)) + (assert ((d)->len > 0), Dynarr_verify_mod (d)->len--, \ + Dynarr_at (d, (d)->len)) #define Dynarr_delete(d, i) Dynarr_delete_many (d, i, 1) #define Dynarr_delete_by_pointer(d, p) \ Dynarr_delete_many (d, (p) - ((d)->base), 1)
--- a/src/lread.c Wed Jan 13 03:01:43 2010 -0600 +++ b/src/lread.c Wed Jan 13 04:07:42 2010 -0600 @@ -2154,8 +2154,7 @@ st.instantiate = instantiate; Dynarr_add (the_structure_type_dynarr, st); - return Dynarr_atp (the_structure_type_dynarr, - Dynarr_length (the_structure_type_dynarr) - 1); + return Dynarr_lastp (the_structure_type_dynarr); } void
--- a/src/lrecord.h Wed Jan 13 03:01:43 2010 -0600 +++ b/src/lrecord.h Wed Jan 13 04:07:42 2010 -0600 @@ -1132,14 +1132,14 @@ #define XD_DYNARR_DESC(base_type, sub_desc) \ { XD_BLOCK_PTR, offsetof (base_type, base), XD_INDIRECT(1, 0), {sub_desc} },\ - { XD_INT, offsetof (base_type, cur) }, \ + { XD_INT, offsetof (base_type, len) }, \ { XD_INT_RESET, offsetof (base_type, max), XD_INDIRECT(1, 0) } \ #ifdef NEW_GC #define XD_LISP_DYNARR_DESC(base_type, sub_desc) \ { XD_LISP_OBJECT_BLOCK_PTR, offsetof (base_type, base), \ XD_INDIRECT(1, 0), {sub_desc} }, \ - { XD_INT, offsetof (base_type, cur) }, \ + { XD_INT, offsetof (base_type, len) }, \ { XD_INT_RESET, offsetof (base_type, max), XD_INDIRECT(1, 0) } #endif /* not NEW_GC */
--- a/src/redisplay-output.c Wed Jan 13 03:01:43 2010 -0600 +++ b/src/redisplay-output.c Wed Jan 13 04:07:42 2010 -0600 @@ -513,8 +513,8 @@ block_end = (!Dynarr_length (ddb->runes) ? 0 - : (Dynarr_atp (ddb->runes, Dynarr_length (ddb->runes) - 1)->xpos + - Dynarr_atp (ddb->runes, Dynarr_length (ddb->runes) - 1)->width)); + : (Dynarr_lastp (ddb->runes)->xpos + + Dynarr_lastp (ddb->runes)->width)); #endif /* If the new block type is not text and the cursor status is @@ -690,7 +690,8 @@ cdba = NULL; } - ddl = Dynarr_atp (ddla, line); /* assert line < Dynarr_length (ddla) */ + /* The following will assert line < Dynarr_length (ddla) */ + ddl = Dynarr_atp (ddla, line); ddba = ddl->display_blocks; if (force_start >= 0 && force_start >= ddl->bounds.left_out)
--- a/src/redisplay.c Wed Jan 13 03:01:43 2010 -0600 +++ b/src/redisplay.c Wed Jan 13 04:07:42 2010 -0600 @@ -1160,7 +1160,7 @@ if (Dynarr_length (data->db->runes) < Dynarr_largest (data->db->runes)) { - crb = Dynarr_atp (data->db->runes, Dynarr_length (data->db->runes)); + crb = Dynarr_past_lastp (data->db->runes); local = 0; } else @@ -2436,8 +2436,8 @@ line and there are more glyphs to display then do appropriate processing to not get a continuation glyph. */ - if (*prop != ADD_FAILED - && Dynarr_atp (*prop, 0)->type == PROP_GLYPH + if (*prop != ADD_FAILED + && Dynarr_begin (*prop)->type == PROP_GLYPH && data.ch == '\n') { /* If there are no more glyphs then do the normal @@ -2448,8 +2448,8 @@ this we would have to carry the index around which might be problematic since the fragment is recalculated for each line. */ - if (EQ (Dynarr_end (tmpglyphs)->glyph, - Dynarr_atp (*prop, 0)->data.p_glyph.glyph)) + if (EQ (Dynarr_lastp (tmpglyphs)->glyph, + Dynarr_begin (*prop)->data.p_glyph.glyph)) { Dynarr_free (*prop); *prop = 0; @@ -2914,7 +2914,7 @@ db->start_pos = dl->bounds.left_in; if (Dynarr_length (db->runes)) { - struct rune *rb = Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1); + struct rune *rb = Dynarr_lastp (db->runes); db->end_pos = rb->xpos + rb->width; } @@ -3829,8 +3829,7 @@ if (Dynarr_length (db->runes)) { - struct rune *rb = - Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1); + struct rune *rb = Dynarr_lastp (db->runes); c_pixpos = rb->xpos + rb->width; } else @@ -3867,14 +3866,14 @@ strdata = XSTRING_DATA (result_str); for (elt = 0, len = 0; elt < Dynarr_length (db->runes); elt++) - { - if (Dynarr_atp (db->runes, elt)->type == RUNE_CHAR) - { - len += (set_itext_ichar - (strdata + len, Dynarr_atp (db->runes, - elt)->object.chr.ch)); - } - } + { + if (Dynarr_atp (db->runes, elt)->type == RUNE_CHAR) + { + len += (set_itext_ichar + (strdata + len, Dynarr_atp (db->runes, + elt)->object.chr.ch)); + } + } init_string_ascii_begin (result_str); bump_string_modiff (result_str); @@ -5162,7 +5161,7 @@ db->start_pos = dl->bounds.left_in; if (Dynarr_length (db->runes)) { - struct rune *rb = Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1); + struct rune *rb = Dynarr_lastp (db->runes); db->end_pos = rb->xpos + rb->width; } @@ -6115,7 +6114,7 @@ { if (!MINI_WINDOW_P (w) && scroll_on_clipped_lines) { - dl = Dynarr_atp (dla, Dynarr_length (dla) - 1); + dl = Dynarr_lastp (dla); if (point >= (dl->charpos + dl->offset) && point <= (dl->end_charpos + dl->offset)) @@ -7594,7 +7593,7 @@ if (gba) { glyph_block *gb = Dynarr_atp (gba, 0); - glyph_block *gb_last = Dynarr_atp (gba, Dynarr_length (gba)); + glyph_block *gb_last = Dynarr_past_lastp (gba); for (; gb < gb_last; gb++) { @@ -7611,20 +7610,20 @@ void mark_redisplay_structs (display_line_dynarr *dla) { - display_line *dl = Dynarr_atp (dla, 0); - display_line *dl_last = Dynarr_atp (dla, Dynarr_length (dla)); + display_line *dl = Dynarr_begin (dla); + display_line *dl_last = Dynarr_past_lastp (dla); for (; dl < dl_last; dl++) { display_block_dynarr *dba = dl->display_blocks; - display_block *db = Dynarr_atp (dba, 0); - display_block *db_last = Dynarr_atp (dba, Dynarr_length (dba)); + display_block *db = Dynarr_begin (dba); + display_block *db_last = Dynarr_past_lastp (dba); for (; db < db_last; db++) { rune_dynarr *ra = db->runes; - rune *r = Dynarr_atp (ra, 0); - rune *r_last = Dynarr_atp (ra, Dynarr_length (ra)); + rune *r = Dynarr_begin (ra); + rune *r_last = Dynarr_past_lastp (ra); for (; r < r_last; r++) { @@ -7743,7 +7742,7 @@ if (!Dynarr_length (cache)) return -1; else - return Dynarr_atp (cache, Dynarr_length (cache) - 1)->end; + return Dynarr_lastp (cache)->end; } /* Return the index of the line POINT is contained within in window @@ -8380,9 +8379,8 @@ return; } - start = Dynarr_atp (internal_cache, 0)->start; - end = - Dynarr_atp (internal_cache, Dynarr_length (internal_cache) - 1)->end; + start = Dynarr_begin (internal_cache)->start; + end = Dynarr_lastp (internal_cache)->end; /* We aren't allowed to generate additional information to fill in gaps, so if the DESIRED structs don't overlap the cache, reset the @@ -8544,11 +8542,11 @@ /* Readjust the high_bound to account for any changes made while correcting the low_bound. */ - high_bound = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end; + high_bound = Dynarr_lastp (cache)->end; if (to > high_bound) { - Charbpos startp = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end + 1; + Charbpos startp = Dynarr_lastp (cache)->end + 1; do { @@ -8560,7 +8558,7 @@ Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0), Dynarr_length (internal_cache)); - high_bound = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end; + high_bound = Dynarr_lastp (cache)->end; startp = high_bound + 1; } while (to > high_bound); @@ -8650,7 +8648,7 @@ if (Dynarr_length (dla)) { - struct display_line *dl = Dynarr_atp (dla, Dynarr_length (dla) - 1); + struct display_line *dl = Dynarr_lastp (dla); *pix_y = dl->ypos + dl->descent - dl->clip; } else @@ -9067,13 +9065,9 @@ else { if (dl->modeline) - *modeline_closest = - Dynarr_atp (db->runes, - Dynarr_length (db->runes) - 1)->charpos; + *modeline_closest = Dynarr_lastp (db->runes)->charpos; else - *closest = - Dynarr_atp (db->runes, - Dynarr_length (db->runes) - 1)->charpos; + *closest = Dynarr_lastp (db->runes)->charpos; } if (dl->modeline)