COMMON: Replace x + ARRAYSIZE(x) by the simpler ARRAYEND(x).

This commit is contained in:
Christoph Mallon 2011-08-07 10:19:30 +02:00
parent e3e0a317e7
commit ab80b20a30
10 changed files with 32 additions and 27 deletions

View file

@ -123,7 +123,7 @@ protected:
VorbisStream::VorbisStream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag dispose) :
_inStream(inStream, dispose),
_length(0, 1000),
_bufferEnd(_buffer + ARRAYSIZE(_buffer)) {
_bufferEnd(ARRAYEND(_buffer)) {
int res = ov_open_callbacks(inStream, &_ovFile, NULL, 0, g_stream_wrap);
if (res < 0) {

View file

@ -707,7 +707,7 @@ int8 MaxTrax::noteOn(ChannelContext &channel, const byte note, uint16 volume, ui
if ((channel.flags & ChannelContext::kFlagMono) == 0) {
voiceNum = pickvoice((channel.flags & ChannelContext::kFlagRightChannel) != 0 ? 1 : 0, pri);
} else {
VoiceContext *voice = _voiceCtx + ARRAYSIZE(_voiceCtx) - 1;
VoiceContext *voice = ARRAYEND(_voiceCtx) - 1;
for (voiceNum = ARRAYSIZE(_voiceCtx) - 1; voiceNum >= 0 && voice->channel != &channel; --voiceNum, --voice)
;
if (voiceNum < 0)

View file

@ -58,6 +58,11 @@ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
*/
#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
/**
* Compute a pointer to one past the last element of an array.
*/
#define ARRAYEND(x) ((x) + ARRAYSIZE((x)))
/**
* @def SCUMMVM_CURRENT_FUNCTION

View file

@ -331,7 +331,7 @@ const TypeTable gameTable[] = {
};
byte getGameID(int game) {
return std::find(gameTable, gameTable + ARRAYSIZE(gameTable) - 1, game)->value;
return std::find(gameTable, ARRAYEND(gameTable) - 1, game)->value;
}
const TypeTable languageTable[] = {
@ -347,7 +347,7 @@ const TypeTable languageTable[] = {
};
byte getLanguageID(int lang) {
return std::find(languageTable, languageTable + ARRAYSIZE(languageTable) - 1, lang)->value;
return std::find(languageTable, ARRAYEND(languageTable) - 1, lang)->value;
}
const TypeTable platformTable[] = {
@ -360,7 +360,7 @@ const TypeTable platformTable[] = {
};
byte getPlatformID(int platform) {
return std::find(platformTable, platformTable + ARRAYSIZE(platformTable) - 1, platform)->value;
return std::find(platformTable, ARRAYEND(platformTable) - 1, platform)->value;
}
const TypeTable specialTable[] = {
@ -373,7 +373,7 @@ const TypeTable specialTable[] = {
};
byte getSpecialID(int special) {
return std::find(specialTable, specialTable + ARRAYSIZE(specialTable) - 1, special)->value;
return std::find(specialTable, ARRAYEND(specialTable) - 1, special)->value;
}
// filename processing

View file

@ -127,7 +127,7 @@ const ExtractType *findExtractType(const int type) {
}
byte getTypeID(int type) {
return std::find(typeTable, typeTable + ARRAYSIZE(typeTable) - 1, type)->value;
return std::find(typeTable, ARRAYEND(typeTable) - 1, type)->value;
}
// Extractor implementation

View file

@ -1084,7 +1084,7 @@ void KyraEngine_HoF::loadNPCScript() {
#pragma mark -
void KyraEngine_HoF::resetScaleTable() {
Common::set_to(_scaleTable, _scaleTable + ARRAYSIZE(_scaleTable), 0x100);
Common::set_to(_scaleTable, ARRAYEND(_scaleTable), 0x100);
}
void KyraEngine_HoF::setScaleTableItem(int item, int data) {
@ -1674,7 +1674,7 @@ void KyraEngine_HoF::setCauldronState(uint8 state, bool paletteFade) {
}
void KyraEngine_HoF::clearCauldronTable() {
Common::set_to(_cauldronTable, _cauldronTable+ARRAYSIZE(_cauldronTable), -1);
Common::set_to(_cauldronTable, ARRAYEND(_cauldronTable), -1);
}
void KyraEngine_HoF::addFrontCauldronTable(int item) {

View file

@ -95,7 +95,7 @@ void KyraEngine_HoF::enterNewScene(uint16 newScene, int facing, int unk1, int un
_emc->run(&_sceneScriptState);
}
Common::for_each(_wsaSlots, _wsaSlots+ARRAYSIZE(_wsaSlots), Common::mem_fun(&WSAMovie_v2::close));
Common::for_each(_wsaSlots, ARRAYEND(_wsaSlots), Common::mem_fun(&WSAMovie_v2::close));
_specialExitCount = 0;
memset(_specialExitTable, -1, sizeof(_specialExitTable));

View file

@ -83,7 +83,7 @@ void KyraEngine_MR::enterNewScene(uint16 sceneId, int facing, int unk1, int unk2
}
_specialExitCount = 0;
Common::set_to(_specialExitTable, _specialExitTable+ARRAYSIZE(_specialExitTable), 0xFFFF);
Common::set_to(_specialExitTable, ARRAYEND(_specialExitTable), 0xFFFF);
_mainCharacter.sceneId = sceneId;
_sceneList[sceneId].flags &= ~1;
@ -388,7 +388,7 @@ void KyraEngine_MR::initSceneScript(int unk1) {
strcat(filename, ".CPS");
_screen->loadBitmap(filename, 3, 3, 0);
Common::set_to(_specialSceneScriptState, _specialSceneScriptState+ARRAYSIZE(_specialSceneScriptState), false);
Common::set_to(_specialSceneScriptState, ARRAYEND(_specialSceneScriptState), false);
_sceneEnterX1 = 160;
_sceneEnterY1 = 0;
_sceneEnterX2 = 296;

View file

@ -80,7 +80,7 @@ const IndexTable iGameTable[] = {
};
byte getGameID(const GameFlags &flags) {
return Common::find(iGameTable, iGameTable + ARRAYSIZE(iGameTable) - 1, flags.gameID)->value;
return Common::find(iGameTable, ARRAYEND(iGameTable) - 1, flags.gameID)->value;
}
const IndexTable iLanguageTable[] = {
@ -95,7 +95,7 @@ const IndexTable iLanguageTable[] = {
};
byte getLanguageID(const GameFlags &flags) {
return Common::find(iLanguageTable, iLanguageTable + ARRAYSIZE(iLanguageTable) - 1, flags.lang)->value;
return Common::find(iLanguageTable, ARRAYEND(iLanguageTable) - 1, flags.lang)->value;
}
const IndexTable iPlatformTable[] = {
@ -108,7 +108,7 @@ const IndexTable iPlatformTable[] = {
};
byte getPlatformID(const GameFlags &flags) {
return Common::find(iPlatformTable, iPlatformTable + ARRAYSIZE(iPlatformTable) - 1, flags.platform)->value;
return Common::find(iPlatformTable, ARRAYEND(iPlatformTable) - 1, flags.platform)->value;
}
byte getSpecialID(const GameFlags &flags) {

View file

@ -38,30 +38,30 @@ public:
const int arraySorted[] = { 1, 2, 3, 3, 4, 5 };
const int arrayUnsorted[] = { 5, 3, 1, 2, 4, 3 };
TS_ASSERT_EQUALS(checkSort(arraySorted, arraySorted + ARRAYSIZE(arraySorted), Common::Less<int>()), true);
TS_ASSERT_EQUALS(checkSort(arraySorted, arraySorted + ARRAYSIZE(arraySorted), Common::Greater<int>()), false);
TS_ASSERT_EQUALS(checkSort(arraySorted, ARRAYEND(arraySorted), Common::Less<int>()), true);
TS_ASSERT_EQUALS(checkSort(arraySorted, ARRAYEND(arraySorted), Common::Greater<int>()), false);
TS_ASSERT_EQUALS(checkSort(arrayUnsorted, arrayUnsorted + ARRAYSIZE(arrayUnsorted), Common::Less<int>()), false);
TS_ASSERT_EQUALS(checkSort(arrayUnsorted, arrayUnsorted + ARRAYSIZE(arrayUnsorted), Common::Greater<int>()), false);
TS_ASSERT_EQUALS(checkSort(arrayUnsorted, ARRAYEND(arrayUnsorted), Common::Less<int>()), false);
TS_ASSERT_EQUALS(checkSort(arrayUnsorted, ARRAYEND(arrayUnsorted), Common::Greater<int>()), false);
}
void test_pod_sort() {
{
int array[] = { 63, 11, 31, 72, 1, 48, 32, 69, 38, 31 };
Common::sort(array, array + ARRAYSIZE(array));
TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), true);
Common::sort(array, ARRAYEND(array));
TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true);
// already sorted
Common::sort(array, array + ARRAYSIZE(array));
TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), true);
Common::sort(array, ARRAYEND(array));
TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true);
}
{
int array[] = { 90, 80, 70, 60, 50, 40, 30, 20, 10 };
Common::sort(array, array + ARRAYSIZE(array));
TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Less<int>()), true);
Common::sort(array, ARRAYEND(array));
TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true);
Common::sort(array, array + ARRAYSIZE(array), Common::Greater<int>());
TS_ASSERT_EQUALS(checkSort(array, array + ARRAYSIZE(array), Common::Greater<int>()), true);
Common::sort(array, ARRAYEND(array), Common::Greater<int>());
TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Greater<int>()), true);
}
}