Skip to content

Commit 20cf78d

Browse files
authored
Use xxh3.HashString128 instead of converting to byte slice (#2365)
1 parent 4569707 commit 20cf78d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

internal/execute/incremental/snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (f *FileInfo) AffectsGlobalScope() bool { return f.affectsGlo
2929
func (f *FileInfo) ImpliedNodeFormat() core.ResolutionMode { return f.impliedNodeFormat }
3030

3131
func ComputeHash(text string, hashWithText bool) string {
32-
hashBytes := xxh3.Hash128([]byte(text)).Bytes()
32+
hashBytes := xxh3.HashString128(text).Bytes()
3333
hash := hex.EncodeToString(hashBytes[:])
3434
if hashWithText {
3535
hash += "-" + text

internal/project/overlayfs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func newDiskFile(fileName string, content string) *diskFile {
7878
fileBase: fileBase{
7979
fileName: fileName,
8080
content: content,
81-
hash: xxh3.Hash128([]byte(content)),
81+
hash: xxh3.HashString128(content),
8282
},
8383
}
8484
}
@@ -125,7 +125,7 @@ func newOverlay(fileName string, content string, version int32, kind core.Script
125125
fileBase: fileBase{
126126
fileName: fileName,
127127
content: content,
128-
hash: xxh3.Hash128([]byte(content)),
128+
hash: xxh3.HashString128(content),
129129
},
130130
version: version,
131131
kind: kind,
@@ -154,7 +154,7 @@ func (o *Overlay) computeMatchesDiskText(fs vfs.FS) bool {
154154
if !ok {
155155
return false
156156
}
157-
return xxh3.Hash128([]byte(diskContent)) == o.hash
157+
return xxh3.HashString128(diskContent) == o.hash
158158
}
159159

160160
func (o *Overlay) IsOverlay() bool {
@@ -348,7 +348,7 @@ func (fs *overlayFS) processChanges(changes []FileChange) (FileChangeSummary, ma
348348
}
349349
if len(change.Changes) > 0 {
350350
o.version = change.Version
351-
o.hash = xxh3.Hash128([]byte(o.content))
351+
o.hash = xxh3.HashString128(o.content)
352352
o.matchesDiskText = false
353353
newOverlays[path] = o
354354
}

internal/project/snapshotfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (s *snapshotFSBuilder) GetFileByPath(fileName string, path tspath.Path) Fil
119119
if content, ok := s.fs.ReadFile(fileName); ok {
120120
entry.Change(func(file *diskFile) {
121121
file.content = content
122-
file.hash = xxh3.Hash128([]byte(content))
122+
file.hash = xxh3.HashString128(content)
123123
file.needsReload = false
124124
})
125125
} else {

0 commit comments

Comments
 (0)