Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppose we have `m map[intern.ID]T` and `s string`. We want to query if this string is in the map. We could write `m[table.Intern(s)]`, but if `s` is not already interned, this is quite wasteful! Interning a never-before-seen string costs three map hits, plus the hit to `m`. However, if `s` is not interned, it cannot possibly be in `m`, so we can cut the cost of every lookup to one hit in `Query` and one in `m[id]`. In other words, this lets us write this function: ```go func get(tab intern.Table, m map[intern.ID]T, s string) (T, bool) { id, ok := tab.Query(s) if !ok { return T{}, false } v, ok := m[id] return v, ok } ``` char6-inlined IDs are treated as always being interned, which means that for very small IDs, we only have to hit one map: the lookup in `m[id]`.
- Loading branch information