From 3268bee39660ceba12e8206a88c461afce8ebb18 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Mon, 3 Sep 2018 11:10:09 +1000 Subject: [PATCH] Prepare for release 1.9.0 --- main.go | 6 ++-- processor/workers.go | 70 +++++++++++++++++++++----------------------- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/main.go b/main.go index fbc97627c..75797a688 100644 --- a/main.go +++ b/main.go @@ -8,9 +8,9 @@ import ( //go:generate go run scripts/include.go func main() { - // f, _ := os.Create("scc.pprof") - // pprof.StartCPUProfile(f) - // defer pprof.StopCPUProfile() + //f, _ := os.Create("scc.pprof") + //pprof.StartCPUProfile(f) + //defer pprof.StopCPUProfile() // defer profile.Start(profile.CPUProfile).Stop() // defer profile.Start(profile.MemProfile).Stop() diff --git a/processor/workers.go b/processor/workers.go index b5a847db2..c12941745 100644 --- a/processor/workers.go +++ b/processor/workers.go @@ -236,8 +236,7 @@ func CountStats(fileJob *FileJob) { // Check if this file is binary by checking for nul byte and if so bail out // this is how GNU Grep, git and ripgrep check for binary files - // TODO limit this to the first 10000 chars - if isBinary(fileJob.Content[index]) { + if index < 10000 && isBinary(fileJob.Content[index]) { fileJob.Binary = true return } @@ -248,41 +247,7 @@ func CountStats(fileJob *FileJob) { if !isWhitespace(fileJob.Content[index]) { state: switch { - case currentState == S_BLANK || currentState == S_MULTICOMMENT_BLANK: - // From blank we can move into comment, move into a multiline comment - // or move into code but we can only do one. - if checkForMatch(fileJob.Content[index], index, endPoint, singleLineCommentChecks, fileJob) { - currentState = S_COMMENT - break state - } - - if nested || len(endComments) == 0 { - offsetJump, endString = checkForMatchMultiOpen(fileJob.Content[index], index, endPoint, multiLineCommentChecks, fileJob) - if offsetJump != 0 { - endComments = append(endComments, endString) - currentState = S_MULTICOMMENT - index += offsetJump - 1 - break state - } - } - - // TODO test if moving this line up above comment checks improves performance - offsetJump, endString = checkForMatchMultiOpen(fileJob.Content[index], index, endPoint, stringChecks, fileJob) - if offsetJump != 0 { - currentState = S_STRING - break state - } - - - currentState = S_CODE - if !Complexity { - offsetJump = checkComplexity(fileJob.Content[index], index, endPoint, complexityChecks, complexityBytes, fileJob) - if offsetJump != 0 { - fileJob.Complexity++ - } - } case currentState == S_CODE: - // From code we can move into a multiline comment or string if nested || len(endComments) == 0 { offsetJump, endString = checkForMatchMultiOpen(fileJob.Content[index], index, endPoint, multiLineCommentChecks, fileJob) if offsetJump != 0 { @@ -348,6 +313,39 @@ func CountStats(fileJob *FileJob) { index += offsetJump - 1 } + case currentState == S_BLANK || currentState == S_MULTICOMMENT_BLANK: + // From blank we can move into comment, move into a multiline comment + // or move into code but we can only do one. + if checkForMatch(fileJob.Content[index], index, endPoint, singleLineCommentChecks, fileJob) { + currentState = S_COMMENT + break state + } + + if nested || len(endComments) == 0 { + offsetJump, endString = checkForMatchMultiOpen(fileJob.Content[index], index, endPoint, multiLineCommentChecks, fileJob) + if offsetJump != 0 { + endComments = append(endComments, endString) + currentState = S_MULTICOMMENT + index += offsetJump - 1 + break state + } + } + + // TODO test if moving this line up above comment checks improves performance + offsetJump, endString = checkForMatchMultiOpen(fileJob.Content[index], index, endPoint, stringChecks, fileJob) + if offsetJump != 0 { + currentState = S_STRING + break state + } + + + currentState = S_CODE + if !Complexity { + offsetJump = checkComplexity(fileJob.Content[index], index, endPoint, complexityChecks, complexityBytes, fileJob) + if offsetJump != 0 { + fileJob.Complexity++ + } + } } }