- if(last_image && !strcasecmp(last_image, title))
- {
- return last_pointer;
- }
- else
-// Search for image anew.
- for(int i = 0; i < contents.total; i++)
- {
- if(!strcasecmp(contents.values[i], title))
- {
- last_pointer = pointers.values[i];
- last_image = contents.values[i];
- used.values[i] = 1;
- return pointers.values[i];
+ if( last_image && !strcasecmp(last_image->name, name) )
+ return last_image->data;
+
+// look forwards thru data sets for name
+ int start_item = 0;
+ for( int i=0,n=data_items.size(); i<n; ++i ) {
+ int end_item = start_item + data_items[i];
+ int r = end_item, l = start_item-1;
+// binary search for image
+ int m = 0, v = -1;
+ while( r-l > 1 ) {
+ m = (l + r) / 2;
+ image_item *item = images[m];
+ if( !(v=strcasecmp(name, item->name)) ) {
+ item->used = 1;
+ last_image = item;
+ return item->data;
+ }
+ if( v > 0 ) l = m; else r = m;