Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Jan 11, 2024
1 parent c793b46 commit 11de480
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions migrations/legacy_string_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type LegacyStringValue struct {
var _ interpreter.Value = &LegacyStringValue{}

func (v *LegacyStringValue) HashInput(_ *interpreter.Interpreter, _ interpreter.LocationRange, scratch []byte) []byte {
// Use the un-normalized `v.RawStr` for generating the hash.
length := 1 + len(v.RawStr)
// Use the un-normalized `v.UnnormalizedStr` for generating the hash.
length := 1 + len(v.UnnormalizedStr)
var buffer []byte
if length <= len(scratch) {
buffer = scratch[:length]
Expand All @@ -41,6 +41,6 @@ func (v *LegacyStringValue) HashInput(_ *interpreter.Interpreter, _ interpreter.
}

Check warning on line 41 in migrations/legacy_string_value.go

View check run for this annotation

Codecov / codecov/patch

migrations/legacy_string_value.go#L40-L41

Added lines #L40 - L41 were not covered by tests

buffer[0] = byte(interpreter.HashInputTypeString)
copy(buffer[1:], v.RawStr)
copy(buffer[1:], v.UnnormalizedStr)
return buffer
}
4 changes: 2 additions & 2 deletions migrations/string_normalization/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func TestStringNormalizingMigration(t *testing.T) {

newLegacyStringValue := func(s string) *interpreter.StringValue {
return &interpreter.StringValue{
Str: s,
RawStr: s,
Str: s,
UnnormalizedStr: s,
}
}

Expand Down
10 changes: 5 additions & 5 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,18 +1015,18 @@ type StringValue struct {
// graphemes is a grapheme cluster segmentation iterator,
// which is initialized lazily and reused/reset in functions
// that are based on grapheme clusters
graphemes *uniseg.Graphemes
Str string
RawStr string
graphemes *uniseg.Graphemes
Str string
UnnormalizedStr string
// length is the cached length of the string, based on grapheme clusters.
// a negative value indicates the length has not been initialized, see Length()
length int
}

func NewUnmeteredStringValue(str string) *StringValue {
return &StringValue{
Str: norm.NFC.String(str),
RawStr: str,
Str: norm.NFC.String(str),
UnnormalizedStr: str,
// a negative value indicates the length has not been initialized, see Length()
length: -1,
}
Expand Down

0 comments on commit 11de480

Please sign in to comment.