瀏覽代碼

Add draft of map_get for array-like access optimization

pull/5/head
mtardy 4 年之前
父節點
當前提交
f8078c49d5
共有 2 個檔案被更改,包括 13 行新增2 行删除
  1. +12
    -1
      object.c
  2. +1
    -1
      parse.leg

+ 12
- 1
object.c 查看文件

@ -177,7 +177,19 @@ ssize_t map_search(oop map, oop key)
{
assert(is(Map, map));
assert(key);
ssize_t l = 0, r = get(map, Map, size) - 1;
/* this optimization can only work if the array is consistent
ie. doesn't start at 3 because of existing member, see map_append
if (is(Integer, key)) {
size_t index = get(key, Integer, value);
if (index > r) {
return -1 - (r + 1);
}
return
}
*/
while (l <= r) {
ssize_t mid = (l + r) / 2;
int cmpres = oopcmp(get(map, Map, elements)[mid].key, key);
@ -370,4 +382,3 @@ oop intern(char *ident)
map_insert(symbol_table, symbol, null, pos);
return symbol;
}

+ 1
- 1
parse.leg 查看文件

@ -230,7 +230,7 @@ postfix = i:value ( DOT s:IDENT a:argumentList { map_set(a, int
| LBRAC p:exp RBRAC !EQUAL { i = newGetIndex(i, p) }
| a:argumentList { i = newCall(i, a) }
) * { $$ = i }
paramList = LPAREN m:makeMap
( i:IDENT { map_append(m, i) }
( COMMA i:IDENT { map_append(m, i) }

Loading…
取消
儲存