summaryrefslogtreecommitdiff
path: root/src/glibext/gwidthtracker.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-08-06 17:38:09 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-08-06 17:38:09 (GMT)
commite59544bb61b0043d82946918ece144cae2749d53 (patch)
tree553447beaf577d573076a2bdf3f694f134c8d8e6 /src/glibext/gwidthtracker.c
parentebfc6a8ebcef2b42beb6ef12e4946bb2f73f2723 (diff)
Fixed many bugs in the code cache and the width tracker objects.
Diffstat (limited to 'src/glibext/gwidthtracker.c')
-rw-r--r--src/glibext/gwidthtracker.c67
1 files changed, 40 insertions, 27 deletions
diff --git a/src/glibext/gwidthtracker.c b/src/glibext/gwidthtracker.c
index 44a7ff0..e116a85 100644
--- a/src/glibext/gwidthtracker.c
+++ b/src/glibext/gwidthtracker.c
@@ -613,8 +613,14 @@ static void g_width_tracker_update_ranges(GWidthTracker *tracker, size_t start,
for (i = start; i < tracker->count; i++)
{
+#ifndef NDEBUG
+ if ((i + 1) < tracker->count)
+ assert((tracker->portions[i].last + 1) == tracker->portions[i + 1].first);
+#endif
+
tracker->portions[i].first += diff;
tracker->portions[i].last += diff;
+
}
}
@@ -746,7 +752,6 @@ void g_width_tracker_update_added(GWidthTracker *tracker, size_t index, size_t c
{
size_t current; /* Indice de portion visée */
common_metrics *portion; /* Portion sélectionnée */
- size_t next; /* Prochaine portion à décaller*/
size_t i; /* Boucle de parcours */
size_t dest; /* Destination d'une recopie */
size_t src; /* Source d'une recopie */
@@ -786,7 +791,9 @@ void g_width_tracker_update_added(GWidthTracker *tracker, size_t index, size_t c
g_width_tracker_reset_widths(tracker, current);
- next = current + 1;
+ /* Suite impérative : accroître les indices ! */
+
+ g_width_tracker_update_ranges(tracker, current + 1, count);
/* Un découpage s'impose-t-il quelque part ? */
@@ -810,14 +817,12 @@ void g_width_tracker_update_added(GWidthTracker *tracker, size_t index, size_t c
memmove(&tracker->portions[dest], &tracker->portions[src],
(tracker->count - src - 1) * sizeof(common_metrics));
- next++;
-
/* Insertion au début */
if (i == portion->first)
{
assert(i == index);
- tracker->portions[current + 1].first = portion->first + 1;
+ tracker->portions[current + 1].first = i + 1;
tracker->portions[current + 1].last = portion->last;
tracker->portions[current + 1].cached = false;
@@ -839,6 +844,8 @@ void g_width_tracker_update_added(GWidthTracker *tracker, size_t index, size_t c
}
+ assert((tracker->portions[current].last + 1) == tracker->portions[current + 1].first);
+
/* Mise à jour des largeurs */
g_width_tracker_reset_widths(tracker, current);
@@ -849,10 +856,6 @@ void g_width_tracker_update_added(GWidthTracker *tracker, size_t index, size_t c
}
- /* Suite impérative : accroître les indices ! */
-
- g_width_tracker_update_ranges(tracker, next, 1);
-
}
@@ -879,6 +882,7 @@ void g_width_tracker_update_deleted(GWidthTracker *tracker, size_t start, size_t
size_t dest; /* Destination du transfert */
bool keep_last; /* Conservation de portion #2 */
size_t src; /* Source du transfert */
+ size_t update; /* Début de la série en rafale */
first = g_width_tracker_find_metrics(tracker, start);
assert(first < tracker->count);
@@ -890,18 +894,19 @@ void g_width_tracker_update_deleted(GWidthTracker *tracker, size_t start, size_t
/* Suppression de portions inutiles ? */
- keep_first = (tracker->portions[first].first < start || end < tracker->portions[first].last);
+ keep_first = (tracker->portions[first].first < start);
dest = (keep_first ? first + 1 : first);
- keep_last = (tracker->portions[last].first < start || end < tracker->portions[last].last);
+ keep_last = (end < tracker->portions[last].last);
src = (keep_last ? last : last + 1);
if (src > dest)
{
- memmove(&tracker->portions[dest], &tracker->portions[src],
- (tracker->count - src) * sizeof(common_metrics));
+ if (src < tracker->count)
+ memmove(&tracker->portions[dest], &tracker->portions[src],
+ (tracker->count - src) * sizeof(common_metrics));
tracker->count -= (src - dest);
@@ -914,10 +919,11 @@ void g_width_tracker_update_deleted(GWidthTracker *tracker, size_t start, size_t
if (keep_first && keep_last && last != first)
{
- tracker->portions[first].last = tracker->portions[dest].last;
+ tracker->portions[first].last = tracker->portions[first + 1].last;
- memmove(&tracker->portions[first + 1], &tracker->portions[first + 2],
- (tracker->count - first - 2) * sizeof(common_metrics));
+ if ((first - 2) < tracker->count)
+ memmove(&tracker->portions[first + 1], &tracker->portions[first + 2],
+ (tracker->count - first - 2) * sizeof(common_metrics));
tracker->count--;
@@ -930,29 +936,36 @@ void g_width_tracker_update_deleted(GWidthTracker *tracker, size_t start, size_t
/* Avant toute chose : faire décroître les indices ! */
- if (keep_first)
+ if (keep_first && keep_last)
{
- if (end < tracker->portions[first].last)
- tracker->portions[first].last -= diff;
- else
- tracker->portions[first].last = start - 1;
+ tracker->portions[first].last -= diff;
+ update = first + 1;
}
- if (keep_last && last != first)
+ else
{
- tracker->portions[dest].first = end + 1;
- tracker->portions[dest].last -= diff;
+ if (keep_first)
+ {
+ tracker->portions[first].last = start - 1;
+ update = first + 1;
+ }
+ else
+ update = first;
+
+ if (keep_last)
+ tracker->portions[update].first = end + 1;
+
}
- g_width_tracker_update_ranges(tracker, keep_last ? dest + 1 : dest, -diff);
+ g_width_tracker_update_ranges(tracker, update, -diff);
/* Mise à jour des largeurs aux extrémités */
if (keep_first)
g_width_tracker_reset_widths(tracker, first);
- if (keep_last && last != first)
- g_width_tracker_reset_widths(tracker, dest);
+ if (keep_last && !keep_first)
+ g_width_tracker_reset_widths(tracker, update);
}