Skip to content

Commit 75b83e9

Browse files
authored
chore: gofmt -w . (#41)
1 parent 1f0931c commit 75b83e9

File tree

3 files changed

+45
-45
lines changed

3 files changed

+45
-45
lines changed

benchmarks_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ func BenchmarkParseSampleFile(b *testing.B) {
2424
b.ResetTimer()
2525
for i := 0; i < b.N; i++ {
2626
p := &Parser{
27-
minLength: 3,
28-
minOccurrences: 2,
29-
supportedTokens: []token.Token{token.STRING},
30-
excludeTypes: map[Type]bool{},
31-
strs: Strings{},
32-
consts: Constants{},
33-
matchConstant: true,
27+
minLength: 3,
28+
minOccurrences: 2,
29+
supportedTokens: []token.Token{token.STRING},
30+
excludeTypes: map[Type]bool{},
31+
strs: Strings{},
32+
consts: Constants{},
33+
matchConstant: true,
3434
evalConstExpressions: false, // Disable for benchmark
35-
stringCount: make(map[string]int),
36-
stringMutex: sync.RWMutex{},
37-
stringCountMutex: sync.RWMutex{},
38-
constMutex: sync.RWMutex{},
35+
stringCount: make(map[string]int),
36+
stringMutex: sync.RWMutex{},
37+
stringCountMutex: sync.RWMutex{},
38+
constMutex: sync.RWMutex{},
3939
}
4040

4141
v := &treeVisitor{
@@ -57,9 +57,9 @@ func BenchmarkRun(b *testing.B) {
5757
}
5858

5959
config := &Config{
60-
MinStringLength: 3,
61-
MinOccurrences: 2,
62-
MatchWithConstants: true,
60+
MinStringLength: 3,
61+
MinOccurrences: 2,
62+
MatchWithConstants: true,
6363
EvalConstExpressions: false, // Disable for benchmark
6464
}
6565

@@ -521,14 +521,14 @@ func BenchmarkParseTreeWithConstMatch(b *testing.B) {
521521
// BenchmarkStringInterning benchmarks the performance improvement from string interning
522522
func BenchmarkStringInterning(b *testing.B) {
523523
b.ReportAllocs()
524-
524+
525525
// Generate some test data
526526
testData := make([]string, 100)
527527
for i := 0; i < 100; i++ {
528528
// Create strings that will sometimes be duplicates
529529
testData[i] = fmt.Sprintf("test-string-%d", i%20)
530530
}
531-
531+
532532
b.ResetTimer()
533533
for i := 0; i < b.N; i++ {
534534
p := New(
@@ -546,12 +546,12 @@ func BenchmarkStringInterning(b *testing.B) {
546546
2,
547547
nil,
548548
)
549-
549+
550550
// Simulate processing these strings
551551
for _, s := range testData {
552552
// Intern the string
553553
interned := InternString(s)
554-
554+
555555
// Do something with the interned string to prevent optimization
556556
if len(interned) > 0 {
557557
p.stringCount[interned]++
@@ -566,20 +566,20 @@ func BenchmarkParseTreeLargeCodebase(b *testing.B) {
566566
if os.Getenv("CI") != "true" && os.Getenv("BENCH_LARGE") != "1" {
567567
b.Skip("Skipping large benchmark; run with BENCH_LARGE=1 to enable")
568568
}
569-
569+
570570
// Use the parent directory of the current workspace as test data
571571
// This gives us a real-world codebase to analyze
572572
wd, err := os.Getwd()
573573
if err != nil {
574574
b.Fatalf("Failed to get working directory: %v", err)
575575
}
576-
576+
577577
// Go up one level to get parent directory
578578
testPath := filepath.Dir(wd)
579-
579+
580580
b.ReportAllocs()
581581
b.ResetTimer()
582-
582+
583583
for i := 0; i < b.N; i++ {
584584
p := New(
585585
testPath,
@@ -606,15 +606,15 @@ func BenchmarkParseTreeLargeCodebase(b *testing.B) {
606606
// BenchmarkStringPooling benchmarks the performance impact of string pooling
607607
func BenchmarkStringPooling(b *testing.B) {
608608
b.ReportAllocs()
609-
609+
610610
// Create a set of strings to process with some duplication
611611
testStrings := make([]string, 10000)
612612
for i := 0; i < len(testStrings); i++ {
613613
testStrings[i] = fmt.Sprintf("test-string-%d", i%500)
614614
}
615-
615+
616616
b.ResetTimer()
617-
617+
618618
for i := 0; i < b.N; i++ {
619619
p := New(
620620
"",
@@ -631,13 +631,13 @@ func BenchmarkStringPooling(b *testing.B) {
631631
2,
632632
nil, // No type exclusions
633633
)
634-
634+
635635
// Simulate processing all strings
636636
for _, s := range testStrings {
637637
// Use intern to ensure string deduplication
638638
internedString := InternString(s)
639639
p.stringCount[internedString]++
640-
640+
641641
// Simulate position tracking (simplified)
642642
if _, ok := p.strs[internedString]; !ok {
643643
p.strs[internedString] = make([]ExtendedPos, 0, 4)
@@ -650,14 +650,14 @@ func BenchmarkStringPooling(b *testing.B) {
650650
func BenchmarkParallelProcessing(b *testing.B) {
651651
// Use the testdata directory which should have multiple files
652652
testPath := filepath.Join(".", "testdata")
653-
653+
654654
// Ensure the test directory exists
655655
if _, err := os.Stat(testPath); os.IsNotExist(err) {
656656
b.Skipf("Test data directory %q does not exist", testPath)
657657
}
658-
658+
659659
b.ReportAllocs()
660-
660+
661661
for i := 0; i < b.N; i++ {
662662
b.StopTimer()
663663
p := New(

testdata/const_expressions.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package testdata
22

33
const (
44
Prefix = "example.com/"
5-
API = Prefix + "api"
6-
Web = Prefix + "web"
5+
API = Prefix + "api"
6+
Web = Prefix + "web"
77
)
88

99
func testConstExpressions() {
1010
// These should match the constant expressions when using -eval-const-expr
1111
a := "example.com/api"
1212
b := "example.com/api"
13-
13+
1414
c := "example.com/web"
1515
d := "example.com/web"
16-
}
16+
}

testdata/match_constant.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const (
77
// Grouped constants
88
GroupedConst1 = "grouped constant"
99
GroupedConst2 = "another grouped"
10-
10+
1111
// Constants with the same value
1212
DuplicateConst1 = "duplicate value"
1313
DuplicateConst2 = "duplicate value"
14-
14+
1515
// Constants with special characters
1616
SpecialConst = "special\nvalue\twith\rchars"
1717
)
@@ -20,7 +20,7 @@ const (
2020
func scopedConstants() {
2121
const LocalConst = "local constant"
2222
str := "local constant" // Should match LocalConst
23-
23+
2424
if true {
2525
const BlockConst = "block constant"
2626
str := "block constant" // Should match BlockConst
@@ -30,27 +30,27 @@ func scopedConstants() {
3030
// Usage of constants from different contexts
3131
func useConstants() {
3232
// Assignment context
33-
str1 := "single constant" // Should match SingleConst
34-
str2 := "grouped constant" // Should match GroupedConst1
35-
str3 := "duplicate value" // Should match DuplicateConst1 (first defined)
33+
str1 := "single constant" // Should match SingleConst
34+
str2 := "grouped constant" // Should match GroupedConst1
35+
str3 := "duplicate value" // Should match DuplicateConst1 (first defined)
3636
str4 := "special\nvalue\twith\rchars" // Should match SpecialConst
37-
37+
3838
// Binary expression context
3939
if str1 == "single constant" {
4040
println("matched")
4141
}
42-
42+
4343
// Case statement context
4444
switch str2 {
4545
case "grouped constant":
4646
println("matched")
4747
}
48-
48+
4949
// Function call context
5050
println("duplicate value")
51-
51+
5252
// Return statement context
5353
func() string {
5454
return "grouped constant"
5555
}()
56-
}
56+
}

0 commit comments

Comments
 (0)