Branch: Tag:

2010-09-27

2010-09-27 21:15:03 by Marcus Comstedt <marcus@mc.pp.se>

Optimized attribute lookup.

110:    };       static array(MatchAttr) attrs = ({}); +  static mapping(string:MatchAttr) macros = ([]);       static int invalid_attr_name(string name)    {
165:    foreach(data/"\n", string line)    handle_attr_line(line, 1);    attrs = reverse(attrs); +  foreach(attrs, MatchAttr a) +  if(a->is_macro) +  macros[a->name] = a; +  attrs = filter(attrs, lambda(MatchAttr a) { return !a->is_macro; });    }       static int path_matches(string path, string pattern)
179:    static void macroexpand_one(string attrname, array(MatchAttr) attrs,    mapping(string:string|int) all_attr)    { -  MatchAttr ma = 0; +     if(all_attr[attrname] != ATTR_TRUE)    return; -  foreach(attrs, MatchAttr a) -  if(a->is_macro && a->name == attrname) -  ma = a; +  MatchAttr ma = macros[attrname];    if(ma) fill_one(ma, attrs, all_attr);    }   
203:    mapping(string:string|int) all_attr)    {    foreach(attrs, MatchAttr a) -  if(!a->is_macro && path_matches(path, a->name)) +  if(/*!a->is_macro &&*/ path_matches(path, a->name))    fill_one(a, attrs, all_attr);    }   
217:    array(string) findattr(string attrname)    {    array(string) r = ({}); -  foreach(attrs, MatchAttr attr) { +  foreach(attrs+values(macros), MatchAttr attr) {    int z=0;    foreach(attr->states, AttrState state)    if(state->attr == attrname && state->setto == ATTR_TRUE) {