Skip to content

Commit

Permalink
Bug fix on eliminating code pairs that cannot meet threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsvajlenko committed Apr 18, 2022
1 parent ef79322 commit 5e2b1ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
11 changes: 5 additions & 6 deletions internal/detection/detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ func DetectClones(pset *parsing.ParseSet, threshold float64) (*CloneSet, error)

for j := i + 1; j < len(functions); j++ {
f2 := functions[j]
if math.Ceil(math.Max(float64(f1.LineLength), float64(f2.LineLength))*threshold) > math.Min(float64(f1.LineLength), float64(f1.LineLength)) {
if isClone(f1, f2, threshold) {
cclones <- Clone{
FunctionId1: f1.Id,
FunctionId2: f2.Id,
}
if isClone(f1, f2, threshold) {
cclones <- Clone{
FunctionId1: f1.Id,
FunctionId2: f2.Id,
}
}
}
Expand All @@ -70,6 +68,7 @@ func isClone(f1 parsing.Function, f2 parsing.Function, threshold float64) bool {
len2 := len(f2.PrettyPrintBody)
reqshared := int(math.Ceil(float64(max(len1, len2)) * threshold))

// Short circuit if not possible to satisfy threshold
if len1 < reqshared || len2 < reqshared {
return false
}
Expand Down
1 change: 0 additions & 1 deletion internal/parsing/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ func parseFile(file File, fset *token.FileSet, intern *sync.Map) ([]Function, []
})
}
}

return retval, errors
}

Expand Down

0 comments on commit 5e2b1ba

Please sign in to comment.