Skip to content

Commit

Permalink
go back to sorting _originalNamePairs lexicographically
Browse files Browse the repository at this point in the history
Now that we only use the list to create a replacer at init time,
we no longer need to spend extra effort sorting by length first.
The benchmark shows no measurable difference in performance.
  • Loading branch information
mvdan authored and lu4p committed Dec 1, 2024
1 parent ef76bf1 commit 30d1d8c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
2 changes: 1 addition & 1 deletion reflect_abi_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package main
// Injected code below this line.

// Each pair is the obfuscated and then the real name.
// The slice is sorted from shortest to longest obfuscated name.
// The pairs are sorted by obfuscated name, lexicographically.
var _originalNamePairs = []string{}

var _originalNamesReplacer *_genericReplacer
Expand Down
8 changes: 1 addition & 7 deletions reflect_abi_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"cmp"
_ "embed"
"fmt"
"maps"
Expand Down Expand Up @@ -67,12 +66,7 @@ func reflectMainPostPatch(file []byte, lpkg *listedPackage, pkg pkgCache) []byte
obfVarName := hashWithPackage(lpkg, "_originalNamePairs")
namePairs := fmt.Appendf(nil, "%s = []string{", obfVarName)

keys := slices.SortedFunc(maps.Keys(pkg.ReflectObjectNames), func(a, b string) int {
if c := cmp.Compare(len(a), len(b)); c != 0 {
return c
}
return cmp.Compare(a, b)
})
keys := slices.Sorted(maps.Keys(pkg.ReflectObjectNames))
namePairsFilled := bytes.Clone(namePairs)
for _, obf := range keys {
namePairsFilled = fmt.Appendf(namePairsFilled, "%q, %q,", obf, pkg.ReflectObjectNames[obf])
Expand Down

0 comments on commit 30d1d8c

Please sign in to comment.