summaryrefslogtreecommitdiff
path: root/oldloader.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-09-23 20:20:08 +0000
committertron <tron@openttd.org>2005-09-23 20:20:08 +0000
commit6ba9c65fc64f774dec8865dee55be8ad2e1d78dc (patch)
treee70c48872cb4fabc6a0a7d5be8307ee160aa77cf /oldloader.c
parentacbccd03ff8fb1becf1fb98ba3e728de3587a2bb (diff)
downloadopenttd-6ba9c65fc64f774dec8865dee55be8ad2e1d78dc.tar.xz
(svn r2979) Avoid unnecessary recursion
Diffstat (limited to 'oldloader.c')
-rw-r--r--oldloader.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/oldloader.c b/oldloader.c
index c751eb003..20f409bda 100644
--- a/oldloader.c
+++ b/oldloader.c
@@ -125,36 +125,26 @@ static byte ReadByte(LoadgameState *ls)
byte. If that byte is negative, we have to repeat the next byte
that many times (+1). Else, we need to read that amount of bytes.
Works pretty good if you have many zero's behind eachother */
- int8 new_byte;
- /* Check if we are reading a chunk */
- if (ls->chunk_size != 0) {
- ls->total_read++;
- ls->chunk_size--;
-
- /* If we are decoding, return the decode_char */
- if (ls->decoding)
- return ls->decode_char;
-
- /* Else return byte from file */
- return ReadByteFromFile(ls);
+ if (ls->chunk_size == 0) {
+ /* Read new chunk */
+ int8 new_byte = ReadByteFromFile(ls);
+
+ if (new_byte < 0) {
+ /* Repeat next char for new_byte times */
+ ls->decoding = true;
+ ls->decode_char = ReadByteFromFile(ls);
+ ls->chunk_size = -new_byte + 1;
+ } else {
+ ls->decoding = false;
+ ls->chunk_size = new_byte + 1;
+ }
}
- /* Read new chunk */
- new_byte = ReadByteFromFile(ls);
-
- if (new_byte < 0) {
- /* Repeat next char for new_byte times */
- ls->decoding = true;
- ls->decode_char = ReadByteFromFile(ls);
- ls->chunk_size = -new_byte + 1;
- } else {
- ls->decoding = false;
- ls->chunk_size = new_byte + 1;
- }
+ ls->total_read++;
+ ls->chunk_size--;
- /* Call this function again to return a byte */
- return ReadByte(ls);
+ return ls->decoding ? ls->decode_char : ReadByteFromFile(ls);
}
/**