summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-08-06 13:55:52 +0000
committerfrosch <frosch@openttd.org>2011-08-06 13:55:52 +0000
commit9e2c2490eb0658eb31d3b1a6358aed78e496b602 (patch)
tree2be4ece869a6877cb85924d569e09653a583ed7a /src
parentf0b723ebaa5af11d7f92248a9f3e52a44c6b5667 (diff)
downloadopenttd-9e2c2490eb0658eb31d3b1a6358aed78e496b602.tar.xz
(svn r22724) -Codechange: Reduce number of realloc calls when loading VarAct2s.
Diffstat (limited to 'src')
-rw-r--r--src/newgrf.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 514d6dfdf..59dc65aad 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -4004,18 +4004,16 @@ static void NewSpriteGroup(ByteReader *buf)
case 2: group->size = DSG_SIZE_DWORD; varsize = 4; break;
}
+ static SmallVector<DeterministicSpriteGroupAdjust, 16> adjusts;
+ adjusts.Clear();
+
/* Loop through the var adjusts. Unfortunately we don't know how many we have
* from the outset, so we shall have to keep reallocing. */
do {
- DeterministicSpriteGroupAdjust *adjust;
-
- group->num_adjusts++;
- group->adjusts = ReallocT(group->adjusts, group->num_adjusts);
-
- adjust = &group->adjusts[group->num_adjusts - 1];
+ DeterministicSpriteGroupAdjust *adjust = adjusts.Append();
/* The first var adjust doesn't have an operation specified, so we set it to add. */
- adjust->operation = group->num_adjusts == 1 ? DSGA_OP_ADD : (DeterministicSpriteGroupAdjustOperation)buf->ReadByte();
+ adjust->operation = adjusts.Length() == 1 ? DSGA_OP_ADD : (DeterministicSpriteGroupAdjustOperation)buf->ReadByte();
adjust->variable = buf->ReadByte();
if (adjust->variable == 0x7E) {
/* Link subroutine group */
@@ -4040,6 +4038,10 @@ static void NewSpriteGroup(ByteReader *buf)
/* Continue reading var adjusts while bit 5 is set. */
} while (HasBit(varadjust, 5));
+ group->num_adjusts = adjusts.Length();
+ group->adjusts = MallocT<DeterministicSpriteGroupAdjust>(group->num_adjusts);
+ MemCpyT(group->adjusts, adjusts.Begin(), group->num_adjusts);
+
group->num_ranges = buf->ReadByte();
if (group->num_ranges > 0) group->ranges = CallocT<DeterministicSpriteGroupRange>(group->num_ranges);