Changeset 4291

Show
Ignore:
Timestamp:
06/10/06 14:23:44 (2 years ago)
Author:
morris
Message:

Optimize indexed searches

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wired/trunk/NEWS

    r4222 r4291  
    55- Fix problem with main thread hanging after registering with a tracker sometimes 
    66- Fixed an issue where, for some types of crashes, wired.pid was not removed at exit 
     7- Optimize indexed searches 
    78 
    891.3 
  • wired/trunk/wired/files.c

    r4286 r4291  
    657657static void wd_files_search_index(wi_string_t *query) { 
    658658        wd_client_t             *client = wd_client(); 
     659        wi_pool_t               *pool = NULL; 
    659660        wi_file_t               *file; 
    660         wi_string_t             *string, *name; 
    661         unsigned int    pathlength, index; 
     661        wi_string_t             *string; 
     662        wi_range_t              range; 
     663        unsigned int    i = 0, pathlength, index; 
    662664         
    663665        wi_rwlock_rdlock(wd_files_index_lock); 
     
    677679                pathlength = 0; 
    678680         
    679         while((string = wi_file_read_line(file))) { 
     681        range.location = 0; 
     682         
     683        while(true) { 
     684                if(!pool) 
     685                        pool = wi_pool_init(wi_pool_alloc()); 
     686                 
     687                string = wi_file_read_line(file); 
     688                 
     689                if(!string) 
     690                        break; 
     691                 
    680692                index = wi_string_index_of_char(string, WD_FIELD_SEPARATOR, 0); 
    681693                 
    682694                if(index != WI_NOT_FOUND) { 
    683                         name = wi_string_substring_to_index(string, index)
    684                          
    685                         if(wi_string_contains_string(name, query, WI_STRING_CASE_INSENSITIVE)) { 
     695                        range.length = index
     696                         
     697                        if(wi_string_index_of_string_in_range(string, query, WI_STRING_CASE_INSENSITIVE, range) != WI_NOT_FOUND) { 
    686698                                wi_string_delete_characters_to_index(string, index + pathlength + 1); 
    687699                                 
     
    689701                        } 
    690702                } 
    691         } 
     703 
     704                if(++i % 100 == 0) { 
     705                        wi_release(pool); 
     706                        pool = NULL; 
     707                } 
     708        } 
     709 
     710        wi_release(pool); 
    692711 
    693712end: