Changeset 52

Show
Ignore:
Timestamp:
08/20/09 12:02:47 (3 years ago)
Author:
amix
Message:

Some miniatur optimization of list_add

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tyrant_manager/extensions/our.lua

    r51 r52  
    3535 
    3636    --- Filter out values so we don't insert duplicates  
    37     local serach_val = LIST_DELIM .. current_value 
     37    local search_val = LIST_DELIM .. current_value 
    3838    local values = _tokenize(value, LIST_DELIM) 
    3939    local filtered = {} 
    4040 
    4141    for i=1, #values do 
    42         if not string.match(serach_val, LIST_DELIM .. values[i] .. LIST_DELIM) then 
     42        if not string.match(search_val, LIST_DELIM .. values[i] .. LIST_DELIM) then 
    4343            table.insert(filtered, values[i]) 
    4444        end 
     
    5151 
    5252    values = filtered 
    53     value = table.concat(values, LIST_DELIM)  .. LIST_DELIM 
    5453 
    5554    --- Check if we should apply cleanup 
    56     local current_list = _current_list(current_value, nil) 
    57     local list_size = #current_list 
    58  
    59     --- If the size is too big then clean up in it 
     55    local list_size = char_count(search_val, LIST_DELIM) 
    6056    list_size = list_size + #values 
    6157 
    6258    if list_size > (limit + 100) then 
     59        local current_list = _current_list(current_value, nil) 
    6360        _list_cleanup(key, current_list, limit, #values) 
    6461    end 
     
    139136    _put(key, result) 
    140137end 
     138 
     139function char_count(str, char)  
     140    if not str then 
     141        return 0 
     142    end 
     143 
     144    local count = 0  
     145    local byte_char = string.byte(char) 
     146    for i = 1, #str do 
     147        if string.byte(str, i) == byte_char then 
     148            count = count + 1  
     149        end  
     150    end  
     151    return count 
     152end