vendor tsgo

This commit is contained in:
2026-07-09 16:50:43 -04:00
parent c06ea2e5a4
commit 98978e4930
5804 changed files with 1556156 additions and 101 deletions

View File

@@ -0,0 +1,44 @@
package build
import (
"sync"
"github.com/microsoft/typescript-go/internal/collections"
)
type parseCacheEntry[V comparable] struct {
value V
mu sync.Mutex
}
type parseCache[K comparable, V comparable] struct {
entries collections.SyncMap[K, *parseCacheEntry[V]]
}
func (c *parseCache[K, V]) loadOrStore(key K, parse func(K) V, allowZero bool) V {
newEntry := &parseCacheEntry[V]{}
newEntry.mu.Lock()
defer newEntry.mu.Unlock()
if entry, loaded := c.entries.LoadOrStore(key, newEntry); loaded {
entry.mu.Lock()
defer entry.mu.Unlock()
if allowZero || entry.value != *new(V) {
return entry.value
}
newEntry = entry
}
newEntry.value = parse(key)
return newEntry.value
}
func (c *parseCache[K, V]) store(key K, value V) {
c.entries.Store(key, &parseCacheEntry[V]{value: value})
}
func (c *parseCache[K, V]) delete(key K) {
c.entries.Delete(key)
}
func (c *parseCache[K, V]) reset() {
c.entries = collections.SyncMap[K, *parseCacheEntry[V]]{}
}