[THOG-315] Replace bytes.buffer with strings.builder. (#533)

* Replace bytes.buffer with string.builder.

* Remove profiling.

* Remove detector changes.

* ignore .test files.

* fix detectors removed.
This commit is contained in:
ahrav 2022-05-10 00:02:46 +00:00 committed by GitHub
parent 80ed2df88f
commit e12432cef8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 5 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
.idea
dist
.env
.env
*.test

View file

@ -76,3 +76,28 @@ func TestGitEngine(t *testing.T) {
}
}
}
func BenchmarkGitEngine(b *testing.B) {
repoUrl := "https://github.com/dustin-decker/secretsandstuff.git"
path, _, err := git.PrepareRepo(repoUrl)
if err != nil {
b.Error(err)
}
defer os.RemoveAll(path)
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
e := Start(ctx,
WithConcurrency(1),
WithDecoders(decoders.DefaultDecoders()...),
WithDetectors(false, DefaultDetectors()...),
)
for i := 0; i < b.N; i++ {
e.ScanGit(ctx, path, "", "", 0, common.FilterEmpty())
resultCount := 0
for _ = range e.ResultsChan() {
resultCount++
}
}
}

View file

@ -332,21 +332,21 @@ func (s *Git) ScanCommits(repo *git.Repository, path string, scanOptions *ScanOp
}
for _, frag := range file.TextFragments {
newLines := bytes.Buffer{}
var sb strings.Builder
newLineNumber := frag.NewPosition
for _, line := range frag.Lines {
if line.Op == gitdiff.OpAdd {
newLines.WriteString(line.Line)
sb.WriteString(line.Line)
}
}
log.WithField("fragment", newLines.String()).Trace("detecting fragment")
log.WithField("fragment", sb.String()).Trace("detecting fragment")
metadata := s.sourceMetadataFunc(fileName, email, hash, when, urlMetadata, newLineNumber)
chunksChan <- &sources.Chunk{
SourceName: s.sourceName,
SourceID: s.sourceID,
SourceType: s.sourceType,
SourceMetadata: metadata,
Data: newLines.Bytes(),
Data: []byte(sb.String()),
Verify: s.verify,
}
}