go back to sorting _originalNamePairs lexicographically

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.
pull/894/head
Daniel Martí 4 months ago committed by Paul Scheduikat
parent ef76bf1c50
commit 30d1d8cbb7

@ -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

@ -2,7 +2,6 @@ package main
import (
"bytes"
"cmp"
_ "embed"
"fmt"
"maps"
@ -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])

Loading…
Cancel
Save