Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 8dc4fea

Browse files
lochelOpenModelica-Hudson
authored andcommitted
Fix ExpandableArray.compress
1 parent 8e2a2a0 commit 8dc4fea

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Compiler/Util/ExpandableArray.mo

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,10 @@ protected
243243
Integer numberOfElements = Dangerous.arrayGetNoBoundsChecking(exarray.numberOfElements, 1);
244244
Integer lastUsedIndex = Dangerous.arrayGetNoBoundsChecking(exarray.lastUsedIndex, 1);
245245
array<Option<T>> data = Dangerous.arrayGetNoBoundsChecking(exarray.data, 1);
246+
Integer i = 0;
246247
algorithm
247-
if numberOfElements == 0 or numberOfElements == lastUsedIndex then
248-
return;
249-
end if;
250-
251-
for i in 1:numberOfElements/2+1 loop
248+
while lastUsedIndex > numberOfElements loop
249+
i := i+1;
252250
if isNone(Dangerous.arrayGetNoBoundsChecking(data, i)) then
253251
Dangerous.arrayUpdateNoBoundsChecking(data, i, Dangerous.arrayGetNoBoundsChecking(data, lastUsedIndex));
254252
Dangerous.arrayUpdateNoBoundsChecking(data, lastUsedIndex, NONE());
@@ -257,7 +255,7 @@ algorithm
257255
lastUsedIndex := lastUsedIndex-1;
258256
end while;
259257
end if;
260-
end for;
258+
end while;
261259

262260
Dangerous.arrayUpdateNoBoundsChecking(exarray.lastUsedIndex, 1, lastUsedIndex);
263261
end compress;

0 commit comments

Comments
 (0)