Skip to content

Commit

Permalink
chore: Use faster 3 way string comparison (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src authored Nov 30, 2024
1 parent a1696fb commit 79fb777
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions bindings/go/scip/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scip

import (
"sort"
"strings"

"golang.org/x/exp/slices"
)
Expand All @@ -24,12 +25,7 @@ func FindSymbol(document *Document, symbolName string) *SymbolInformation {
// and SymbolInformation values must be merged. This guarantee is upheld by CanonicalizeDocument.
func FindSymbolBinarySearch(canonicalizedDocument *Document, symbolName string) *SymbolInformation {
i, found := slices.BinarySearchFunc(canonicalizedDocument.Symbols, symbolName, func(sym *SymbolInformation, lookup string) int {
if sym.Symbol < lookup {
return -1
} else if sym.Symbol == lookup {
return 0
}
return 1
return strings.Compare(sym.Symbol, lookup)
})
if found {
return canonicalizedDocument.Symbols[i]
Expand Down

0 comments on commit 79fb777

Please sign in to comment.