(svn r2979) Avoid unnecessary recursion

This commit is contained in:
tron 2005-09-23 20:20:08 +00:00
parent b1e6b54f94
commit 1b16f210c2

View File

@ -125,36 +125,26 @@ static byte ReadByte(LoadgameState *ls)
byte. If that byte is negative, we have to repeat the next byte 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. that many times (+1). Else, we need to read that amount of bytes.
Works pretty good if you have many zero's behind eachother */ 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) {
if (ls->chunk_size != 0) { /* Read new chunk */
ls->total_read++; int8 new_byte = ReadByteFromFile(ls);
ls->chunk_size--;
/* If we are decoding, return the decode_char */ if (new_byte < 0) {
if (ls->decoding) /* Repeat next char for new_byte times */
return ls->decode_char; ls->decoding = true;
ls->decode_char = ReadByteFromFile(ls);
/* Else return byte from file */ ls->chunk_size = -new_byte + 1;
return ReadByteFromFile(ls); } else {
ls->decoding = false;
ls->chunk_size = new_byte + 1;
}
} }
/* Read new chunk */ ls->total_read++;
new_byte = ReadByteFromFile(ls); ls->chunk_size--;
if (new_byte < 0) { return ls->decoding ? ls->decode_char : ReadByteFromFile(ls);
/* 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;
}
/* Call this function again to return a byte */
return ReadByte(ls);
} }
/** /**