Skip to content

Commit

Permalink
Fix ExpandableArray.compress
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Apr 28, 2017
1 parent 8e2a2a0 commit 8dc4fea
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Compiler/Util/ExpandableArray.mo
Expand Up @@ -243,12 +243,10 @@ protected
Integer numberOfElements = Dangerous.arrayGetNoBoundsChecking(exarray.numberOfElements, 1);
Integer lastUsedIndex = Dangerous.arrayGetNoBoundsChecking(exarray.lastUsedIndex, 1);
array<Option<T>> data = Dangerous.arrayGetNoBoundsChecking(exarray.data, 1);
Integer i = 0;
algorithm
if numberOfElements == 0 or numberOfElements == lastUsedIndex then
return;
end if;

for i in 1:numberOfElements/2+1 loop
while lastUsedIndex > numberOfElements loop
i := i+1;
if isNone(Dangerous.arrayGetNoBoundsChecking(data, i)) then
Dangerous.arrayUpdateNoBoundsChecking(data, i, Dangerous.arrayGetNoBoundsChecking(data, lastUsedIndex));
Dangerous.arrayUpdateNoBoundsChecking(data, lastUsedIndex, NONE());
Expand All @@ -257,7 +255,7 @@ algorithm
lastUsedIndex := lastUsedIndex-1;
end while;
end if;
end for;
end while;

Dangerous.arrayUpdateNoBoundsChecking(exarray.lastUsedIndex, 1, lastUsedIndex);
end compress;
Expand Down

0 comments on commit 8dc4fea

Please sign in to comment.