From 30d1d8cbb7296aa88d2baa94fd98e9316e747ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 1 Dec 2024 16:12:45 +0000 Subject: [PATCH] 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. --- reflect_abi_code.go | 2 +- reflect_abi_patch.go | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/reflect_abi_code.go b/reflect_abi_code.go index 53f467cb..ad944737 100644 --- a/reflect_abi_code.go +++ b/reflect_abi_code.go @@ -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 diff --git a/reflect_abi_patch.go b/reflect_abi_patch.go index 30392e74..7915d235 100644 --- a/reflect_abi_patch.go +++ b/reflect_abi_patch.go @@ -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])