diff options
author | Bjørn Erik Pedersen <[email protected]> | 2019-04-02 20:43:58 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2019-04-02 21:00:42 +0200 |
commit | 4494a01b794ab785c64c8e93c61ccbfa845bc478 (patch) | |
tree | b7401804a188d8b5d5c627b1268c1869f902eb43 /metrics/metrics.go | |
parent | e91e222cd21213961d1e6206e1523bee2c21fa0c (diff) | |
download | hugo-4494a01b794ab785c64c8e93c61ccbfa845bc478.tar.gz hugo-4494a01b794ab785c64c8e93c61ccbfa845bc478.zip |
metrics: Adjust the howSimilar logic vs strings
Also add a test.
Diffstat (limited to 'metrics/metrics.go')
-rw-r--r-- | metrics/metrics.go | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/metrics/metrics.go b/metrics/metrics.go index e67b16bda..329981202 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -27,8 +27,6 @@ import ( "github.com/gohugoio/hugo/compare" "github.com/gohugoio/hugo/common/hreflect" - - "github.com/spf13/cast" ) // The Provider interface defines an interface for measuring metrics. @@ -198,18 +196,17 @@ func (b bySum) Less(i, j int) bool { return b[i].sum > b[j].sum } // howSimilar is a naive diff implementation that returns // a number between 0-100 indicating how similar a and b are. func howSimilar(a, b interface{}) int { - if a == b { - return 100 - } + // TODO(bep) object equality fast path, but remember that + // we can get anytning in here. - as, err1 := cast.ToStringE(a) - bs, err2 := cast.ToStringE(b) + as, ok1 := a.(string) + bs, ok2 := b.(string) - if err1 == nil && err2 == nil { + if ok1 && ok2 { return howSimilarStrings(as, bs) } - if err1 != err2 { + if ok1 != ok2 { return 0 } @@ -219,7 +216,6 @@ func howSimilar(a, b interface{}) int { return 100 } - // TODO(bep) implement ProbablyEq for Pages etc. pe1, pok1 := a.(compare.ProbablyEqer) pe2, pok2 := b.(compare.ProbablyEqer) if pok1 && pok2 && pe1.ProbablyEq(pe2) { |