Skip to content

Commit c76256b

Browse files
committed
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.
1 parent 5483b8b commit c76256b

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎tsc/internal/core/linkstore.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ func (s *PagedLinkStore[V]) Get(key uint64) *V {
6969
}
7070

7171
func (s *PagedLinkStore[V]) Has(key uint64) bool {
72-
return s.TryGet(key) != nil
72+
pageIndex := key >> LinkPageShift
73+
return int(pageIndex) < len(s.pages) && s.pages[pageIndex] != nil && s.pages[pageIndex][key&LinkPageMask] != 0
7374
}
7475

7576
func (s *PagedLinkStore[V]) TryGet(key uint64) *V {

‎tsc/internal/core/linkstore_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package core_test
22

33
import (
4-
"fmt"
54
"runtime"
5+
"strconv"
66
"testing"
77

88
"github.com/microsoft/TypeScript/tsc/internal/core"
@@ -113,17 +113,17 @@ func TestIndexedArenaReachability(t *testing.T) {
113113
var arena core.IndexedArena[*string]
114114
for i := range 4096 {
115115
_, value := arena.New()
116-
*value = new(fmt.Sprint(i))
116+
*value = new(strconv.Itoa(i))
117117
}
118118
runtime.GC()
119119
for i := range 4096 {
120-
assert.Equal(t, **arena.Get(uint32(i + 1)), fmt.Sprint(i))
120+
assert.Equal(t, **arena.Get(uint32(i + 1)), strconv.Itoa(i))
121121
}
122122
}
123123

124124
func BenchmarkPagedLinkStore(b *testing.B) {
125125
for _, stride := range []uint64{1, 16, 256} {
126-
b.Run(fmt.Sprint(stride), func(b *testing.B) {
126+
b.Run(strconv.FormatUint(stride, 10), func(b *testing.B) {
127127
type value struct {
128128
typ *int
129129
flags uint32

0 commit comments

Comments
 (0)