comparison src/redisplay.c @ 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 6540302eedf5
children ea701c23ed84
comparison
equal deleted inserted replaced
4843:715b15990d0a 4844:91b3d00e717f
1158 return ADD_FAILED; 1158 return ADD_FAILED;
1159 } 1159 }
1160 1160
1161 if (Dynarr_length (data->db->runes) < Dynarr_largest (data->db->runes)) 1161 if (Dynarr_length (data->db->runes) < Dynarr_largest (data->db->runes))
1162 { 1162 {
1163 crb = Dynarr_atp (data->db->runes, Dynarr_length (data->db->runes)); 1163 crb = Dynarr_past_lastp (data->db->runes);
1164 local = 0; 1164 local = 0;
1165 } 1165 }
1166 else 1166 else
1167 { 1167 {
1168 crb = &rb; 1168 crb = &rb;
2434 { 2434 {
2435 /* If we just clipped a glyph and we are at the end of a 2435 /* If we just clipped a glyph and we are at the end of a
2436 line and there are more glyphs to display then do 2436 line and there are more glyphs to display then do
2437 appropriate processing to not get a continuation 2437 appropriate processing to not get a continuation
2438 glyph. */ 2438 glyph. */
2439 if (*prop != ADD_FAILED 2439 if (*prop != ADD_FAILED
2440 && Dynarr_atp (*prop, 0)->type == PROP_GLYPH 2440 && Dynarr_begin (*prop)->type == PROP_GLYPH
2441 && data.ch == '\n') 2441 && data.ch == '\n')
2442 { 2442 {
2443 /* If there are no more glyphs then do the normal 2443 /* If there are no more glyphs then do the normal
2444 processing. 2444 processing.
2445 2445
2446 #### This doesn't actually work if the same glyph is 2446 #### This doesn't actually work if the same glyph is
2447 present more than once in the block. To solve 2447 present more than once in the block. To solve
2448 this we would have to carry the index around 2448 this we would have to carry the index around
2449 which might be problematic since the fragment is 2449 which might be problematic since the fragment is
2450 recalculated for each line. */ 2450 recalculated for each line. */
2451 if (EQ (Dynarr_end (tmpglyphs)->glyph, 2451 if (EQ (Dynarr_lastp (tmpglyphs)->glyph,
2452 Dynarr_atp (*prop, 0)->data.p_glyph.glyph)) 2452 Dynarr_begin (*prop)->data.p_glyph.glyph))
2453 { 2453 {
2454 Dynarr_free (*prop); 2454 Dynarr_free (*prop);
2455 *prop = 0; 2455 *prop = 0;
2456 } 2456 }
2457 else { 2457 else {
2912 2912
2913 /* Set the display blocks bounds. */ 2913 /* Set the display blocks bounds. */
2914 db->start_pos = dl->bounds.left_in; 2914 db->start_pos = dl->bounds.left_in;
2915 if (Dynarr_length (db->runes)) 2915 if (Dynarr_length (db->runes))
2916 { 2916 {
2917 struct rune *rb = Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1); 2917 struct rune *rb = Dynarr_lastp (db->runes);
2918 2918
2919 db->end_pos = rb->xpos + rb->width; 2919 db->end_pos = rb->xpos + rb->width;
2920 } 2920 }
2921 else 2921 else
2922 db->end_pos = dl->bounds.right_white; 2922 db->end_pos = dl->bounds.right_white;
3827 max_pixpos - min_pixpos, findex, type, &offset, 3827 max_pixpos - min_pixpos, findex, type, &offset,
3828 Qnil); 3828 Qnil);
3829 3829
3830 if (Dynarr_length (db->runes)) 3830 if (Dynarr_length (db->runes))
3831 { 3831 {
3832 struct rune *rb = 3832 struct rune *rb = Dynarr_lastp (db->runes);
3833 Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1);
3834 c_pixpos = rb->xpos + rb->width; 3833 c_pixpos = rb->xpos + rb->width;
3835 } 3834 }
3836 else 3835 else
3837 c_pixpos = min_pixpos; 3836 c_pixpos = min_pixpos;
3838 3837
3865 data.bytepos - XSTRING_LENGTH (result_str)); 3864 data.bytepos - XSTRING_LENGTH (result_str));
3866 3865
3867 strdata = XSTRING_DATA (result_str); 3866 strdata = XSTRING_DATA (result_str);
3868 3867
3869 for (elt = 0, len = 0; elt < Dynarr_length (db->runes); elt++) 3868 for (elt = 0, len = 0; elt < Dynarr_length (db->runes); elt++)
3870 { 3869 {
3871 if (Dynarr_atp (db->runes, elt)->type == RUNE_CHAR) 3870 if (Dynarr_atp (db->runes, elt)->type == RUNE_CHAR)
3872 { 3871 {
3873 len += (set_itext_ichar 3872 len += (set_itext_ichar
3874 (strdata + len, Dynarr_atp (db->runes, 3873 (strdata + len, Dynarr_atp (db->runes,
3875 elt)->object.chr.ch)); 3874 elt)->object.chr.ch));
3876 } 3875 }
3877 } 3876 }
3878 3877
3879 init_string_ascii_begin (result_str); 3878 init_string_ascii_begin (result_str);
3880 bump_string_modiff (result_str); 3879 bump_string_modiff (result_str);
3881 sledgehammer_check_ascii_begin (result_str); 3880 sledgehammer_check_ascii_begin (result_str);
3882 3881
5160 5159
5161 /* Set the display blocks bounds. */ 5160 /* Set the display blocks bounds. */
5162 db->start_pos = dl->bounds.left_in; 5161 db->start_pos = dl->bounds.left_in;
5163 if (Dynarr_length (db->runes)) 5162 if (Dynarr_length (db->runes))
5164 { 5163 {
5165 struct rune *rb = Dynarr_atp (db->runes, Dynarr_length (db->runes) - 1); 5164 struct rune *rb = Dynarr_lastp (db->runes);
5166 5165
5167 db->end_pos = rb->xpos + rb->width; 5166 db->end_pos = rb->xpos + rb->width;
5168 } 5167 }
5169 else 5168 else
5170 db->end_pos = dl->bounds.right_white; 5169 db->end_pos = dl->bounds.right_white;
6113 6112
6114 if (point >= start && point <= end) 6113 if (point >= start && point <= end)
6115 { 6114 {
6116 if (!MINI_WINDOW_P (w) && scroll_on_clipped_lines) 6115 if (!MINI_WINDOW_P (w) && scroll_on_clipped_lines)
6117 { 6116 {
6118 dl = Dynarr_atp (dla, Dynarr_length (dla) - 1); 6117 dl = Dynarr_lastp (dla);
6119 6118
6120 if (point >= (dl->charpos + dl->offset) 6119 if (point >= (dl->charpos + dl->offset)
6121 && point <= (dl->end_charpos + dl->offset)) 6120 && point <= (dl->end_charpos + dl->offset))
6122 return !dl->clip; 6121 return !dl->clip;
6123 else 6122 else
7592 mark_glyph_block_dynarr (glyph_block_dynarr *gba) 7591 mark_glyph_block_dynarr (glyph_block_dynarr *gba)
7593 { 7592 {
7594 if (gba) 7593 if (gba)
7595 { 7594 {
7596 glyph_block *gb = Dynarr_atp (gba, 0); 7595 glyph_block *gb = Dynarr_atp (gba, 0);
7597 glyph_block *gb_last = Dynarr_atp (gba, Dynarr_length (gba)); 7596 glyph_block *gb_last = Dynarr_past_lastp (gba);
7598 7597
7599 for (; gb < gb_last; gb++) 7598 for (; gb < gb_last; gb++)
7600 { 7599 {
7601 if (!NILP (gb->glyph)) 7600 if (!NILP (gb->glyph))
7602 mark_object (gb->glyph); 7601 mark_object (gb->glyph);
7609 /* See the comment in image_instantiate_cache_result as to why marking 7608 /* See the comment in image_instantiate_cache_result as to why marking
7610 the glyph will also mark the image_instance. */ 7609 the glyph will also mark the image_instance. */
7611 void 7610 void
7612 mark_redisplay_structs (display_line_dynarr *dla) 7611 mark_redisplay_structs (display_line_dynarr *dla)
7613 { 7612 {
7614 display_line *dl = Dynarr_atp (dla, 0); 7613 display_line *dl = Dynarr_begin (dla);
7615 display_line *dl_last = Dynarr_atp (dla, Dynarr_length (dla)); 7614 display_line *dl_last = Dynarr_past_lastp (dla);
7616 7615
7617 for (; dl < dl_last; dl++) 7616 for (; dl < dl_last; dl++)
7618 { 7617 {
7619 display_block_dynarr *dba = dl->display_blocks; 7618 display_block_dynarr *dba = dl->display_blocks;
7620 display_block *db = Dynarr_atp (dba, 0); 7619 display_block *db = Dynarr_begin (dba);
7621 display_block *db_last = Dynarr_atp (dba, Dynarr_length (dba)); 7620 display_block *db_last = Dynarr_past_lastp (dba);
7622 7621
7623 for (; db < db_last; db++) 7622 for (; db < db_last; db++)
7624 { 7623 {
7625 rune_dynarr *ra = db->runes; 7624 rune_dynarr *ra = db->runes;
7626 rune *r = Dynarr_atp (ra, 0); 7625 rune *r = Dynarr_begin (ra);
7627 rune *r_last = Dynarr_atp (ra, Dynarr_length (ra)); 7626 rune *r_last = Dynarr_past_lastp (ra);
7628 7627
7629 for (; r < r_last; r++) 7628 for (; r < r_last; r++)
7630 { 7629 {
7631 if (r->type == RUNE_DGLYPH) 7630 if (r->type == RUNE_DGLYPH)
7632 { 7631 {
7741 line_start_cache_dynarr *cache = w->line_start_cache; 7740 line_start_cache_dynarr *cache = w->line_start_cache;
7742 7741
7743 if (!Dynarr_length (cache)) 7742 if (!Dynarr_length (cache))
7744 return -1; 7743 return -1;
7745 else 7744 else
7746 return Dynarr_atp (cache, Dynarr_length (cache) - 1)->end; 7745 return Dynarr_lastp (cache)->end;
7747 } 7746 }
7748 7747
7749 /* Return the index of the line POINT is contained within in window 7748 /* Return the index of the line POINT is contained within in window
7750 W's line start cache. It will enlarge the cache or move the cache 7749 W's line start cache. It will enlarge the cache or move the cache
7751 window in order to have POINT be present in the cache. MIN_PAST is 7750 window in order to have POINT be present in the cache. MIN_PAST is
8378 { 8377 {
8379 w->line_cache_validation_override--; 8378 w->line_cache_validation_override--;
8380 return; 8379 return;
8381 } 8380 }
8382 8381
8383 start = Dynarr_atp (internal_cache, 0)->start; 8382 start = Dynarr_begin (internal_cache)->start;
8384 end = 8383 end = Dynarr_lastp (internal_cache)->end;
8385 Dynarr_atp (internal_cache, Dynarr_length (internal_cache) - 1)->end;
8386 8384
8387 /* We aren't allowed to generate additional information to fill in 8385 /* We aren't allowed to generate additional information to fill in
8388 gaps, so if the DESIRED structs don't overlap the cache, reset the 8386 gaps, so if the DESIRED structs don't overlap the cache, reset the
8389 cache. */ 8387 cache. */
8390 if (Dynarr_length (cache)) 8388 if (Dynarr_length (cache))
8542 assert (Dynarr_length (cache)); 8540 assert (Dynarr_length (cache));
8543 assert (from >= low_bound); 8541 assert (from >= low_bound);
8544 8542
8545 /* Readjust the high_bound to account for any changes made while 8543 /* Readjust the high_bound to account for any changes made while
8546 correcting the low_bound. */ 8544 correcting the low_bound. */
8547 high_bound = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end; 8545 high_bound = Dynarr_lastp (cache)->end;
8548 8546
8549 if (to > high_bound) 8547 if (to > high_bound)
8550 { 8548 {
8551 Charbpos startp = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end + 1; 8549 Charbpos startp = Dynarr_lastp (cache)->end + 1;
8552 8550
8553 do 8551 do
8554 { 8552 {
8555 regenerate_window (w, startp, point, CMOTION_DISP); 8553 regenerate_window (w, startp, point, CMOTION_DISP);
8556 update_internal_cache_list (w, CMOTION_DISP); 8554 update_internal_cache_list (w, CMOTION_DISP);
8558 /* See comment above about regenerate_window failing. */ 8556 /* See comment above about regenerate_window failing. */
8559 assert (Dynarr_length (internal_cache)); 8557 assert (Dynarr_length (internal_cache));
8560 8558
8561 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0), 8559 Dynarr_add_many (cache, Dynarr_atp (internal_cache, 0),
8562 Dynarr_length (internal_cache)); 8560 Dynarr_length (internal_cache));
8563 high_bound = Dynarr_atp (cache, Dynarr_length (cache) - 1)->end; 8561 high_bound = Dynarr_lastp (cache)->end;
8564 startp = high_bound + 1; 8562 startp = high_bound + 1;
8565 } 8563 }
8566 while (to > high_bound); 8564 while (to > high_bound);
8567 } 8565 }
8568 8566
8648 8646
8649 char_y -= num_disp_lines; 8647 char_y -= num_disp_lines;
8650 8648
8651 if (Dynarr_length (dla)) 8649 if (Dynarr_length (dla))
8652 { 8650 {
8653 struct display_line *dl = Dynarr_atp (dla, Dynarr_length (dla) - 1); 8651 struct display_line *dl = Dynarr_lastp (dla);
8654 *pix_y = dl->ypos + dl->descent - dl->clip; 8652 *pix_y = dl->ypos + dl->descent - dl->clip;
8655 } 8653 }
8656 else 8654 else
8657 *pix_y = WINDOW_TEXT_TOP (w); 8655 *pix_y = WINDOW_TEXT_TOP (w);
8658 8656
9065 *closest = Dynarr_atp (db->runes, 0)->charpos; 9063 *closest = Dynarr_atp (db->runes, 0)->charpos;
9066 } 9064 }
9067 else 9065 else
9068 { 9066 {
9069 if (dl->modeline) 9067 if (dl->modeline)
9070 *modeline_closest = 9068 *modeline_closest = Dynarr_lastp (db->runes)->charpos;
9071 Dynarr_atp (db->runes,
9072 Dynarr_length (db->runes) - 1)->charpos;
9073 else 9069 else
9074 *closest = 9070 *closest = Dynarr_lastp (db->runes)->charpos;
9075 Dynarr_atp (db->runes,
9076 Dynarr_length (db->runes) - 1)->charpos;
9077 } 9071 }
9078 9072
9079 if (dl->modeline) 9073 if (dl->modeline)
9080 *modeline_closest += dl->offset; 9074 *modeline_closest += dl->offset;
9081 else 9075 else