Chameleon

Chameleon Commit Details

Date:2010-07-25 05:28:46 (13 years 8 months ago)
Author:Evan Lojewski
Commit:239
Parents: 238
Message:Converted embedded them loop to a binary search. Maximum loop is now log2(n). Algo could probably be better.
Changes:
M/branches/zef/i386/boot2/gui.c

File differences

branches/zef/i386/boot2/gui.c
177177
178178
179179
180
181
180
181
182
183
184
185
186
187
188
182189
183
184
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
185215
186
216
217
187218
188219
189220
#ifdef EMBED_THEME
static int getEmbeddedImageIndexByName(const char *name)
{
int i;
for (i = 0; i < sizeof(embeddedImages) / sizeof(embeddedImages[0]); i++)
int upperLimit = sizeof(embeddedImages) / sizeof(embeddedImages[0]) - 1;
int lowerLimit = 0;
int compareIndex = (upperLimit - lowerLimit + 1) >> 1; // Midpoint
int result;
// NOTE: This algorithm assumes that the embeddedImages is sorted.
// This is currently done using the make file. If the array is every
// manualy generated, this *will* fail to work properly.
while((result = strcmp(name, embeddedImages[compareIndex].name)) != 0)
{
if (strcmp(name, embeddedImages[i].name) == 0)
return i; // found the name
if(result > 0)// We need to search a HIGHER index
{
if(compareIndex != upperLimit - 1)
{
lowerLimit = compareIndex;
}
else
{
return -1;
}
}
else //if(result < 0) // We Need to search a LOWER index
{
if(compareIndex != lowerLimit + 1)
{
upperLimit = compareIndex;
}
else
{
return -1;
}
}
compareIndex = (upperLimit + lowerLimit + 1) >> 1;// Midpoint
}
return -1;
return compareIndex;
}
#endif

Archive Download the corresponding diff file

Revision: 239