Check link presence without resolving arena indexes

A presence query needs only the page entry, not its value. Resolving
an occupied index adds arena lookup work to a boolean check.

Keep presence checks on the compressed page table, and apply the
repository linter fixes to the link-store tests.
This commit is contained in:
Jake Bailey committed 2026-10-14 09:14:33 -07:00
1 parent 455ef7b3ae
commit 9b5087bfa9
2 files changed
+6 -5

No files matched your search

+2 -1
View File
@@ -69,7 +69,8 @@ func (s *PagedLinkStore[V]) Get(key uint64) *V {
}
func (s *PagedLinkStore[V]) Has(key uint64) bool {
return s.TryGet(key) != nil
pageIndex := key >> LinkPageShift
return int(pageIndex) < len(s.pages) && s.pages[pageIndex] != nil && s.pages[pageIndex][key&LinkPageMask] != 0
}
func (s *PagedLinkStore[V]) TryGet(key uint64) *V {
+4 -4
View File
@@ -1,8 +1,8 @@
package core_test
import (
"fmt"
"runtime"
"strconv"
"testing"
"github.com/microsoft/TypeScript/tsc/internal/core"
@@ -113,17 +113,17 @@ func TestIndexedArenaReachability(t *testing.T) {
var arena core.IndexedArena[*string]
for i := range 4096 {
_, value := arena.New()
*value = new(fmt.Sprint(i))
*value = new(strconv.Itoa(i))
}
runtime.GC()
for i := range 4096 {
assert.Equal(t, **arena.Get(uint32(i + 1)), fmt.Sprint(i))
assert.Equal(t, **arena.Get(uint32(i + 1)), strconv.Itoa(i))
}
}
func BenchmarkPagedLinkStore(b *testing.B) {
for _, stride := range []uint64{1, 16, 256} {
b.Run(fmt.Sprint(stride), func(b *testing.B) {
b.Run(strconv.FormatUint(stride, 10), func(b *testing.B) {
type value struct {
typ *int
flags uint32