Skip to content

Commit bc7f18a

Browse files
committed
perf: remove the log component
1 parent e6d5d66 commit bc7f18a

8 files changed

+0
-66
lines changed

detector.go

-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import (
44
"bytes"
55

66
"github.com/wlynxg/chardet/consts"
7-
"github.com/wlynxg/chardet/log"
87
"github.com/wlynxg/chardet/probe"
9-
"go.uber.org/zap"
108
)
119

1210
// Result represents the character encoding detection result
@@ -26,8 +24,6 @@ type UniversalDetector struct {
2624
// IsoWinMap maps ISO encodings to Windows encodings
2725
IsoWinMap map[string]string
2826

29-
log *zap.SugaredLogger
30-
3127
// done indicates if detection is complete
3228
done bool
3329
// gotData indicates if any data has been processed
@@ -70,7 +66,6 @@ func NewUniversalDetector(filter consts.LangFilter) *UniversalDetector {
7066
consts.ISO885913: consts.Windows1257,
7167
},
7268

73-
log: log.New("UniversalDetector"),
7469
inputState: consts.PureAsciiInputState,
7570
lastChars: []byte{},
7671
filter: filter,
@@ -241,7 +236,6 @@ func (u *UniversalDetector) GetResult() Result {
241236

242237
switch {
243238
case !u.gotData:
244-
u.log.Debug("no data received!")
245239
case u.inputState == consts.PureAsciiInputState:
246240
u.result = Result{
247241
Encoding: consts.Ascii,

log/log.go

-25
This file was deleted.

probe/charset_group_probe.go

-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ package probe
22

33
import (
44
"github.com/wlynxg/chardet/consts"
5-
"github.com/wlynxg/chardet/log"
6-
"go.uber.org/zap"
75
)
86

97
type CharSetGroupProbe struct {
108
CharSetProbe
119

12-
log *zap.SugaredLogger
1310
filter consts.LangFilter
1411
activeNum int
1512
bestGuessProbe Probe
@@ -19,7 +16,6 @@ type CharSetGroupProbe struct {
1916
func NewCharSetGroupProbe(filter consts.LangFilter, probes []Probe) CharSetGroupProbe {
2017
p := CharSetGroupProbe{
2118
CharSetProbe: NewCharSetProbe(filter),
22-
log: log.New("CharSetGroupProbe"),
2319
filter: filter,
2420
activeNum: 0,
2521
bestGuessProbe: nil,
@@ -69,7 +65,6 @@ func (c *CharSetGroupProbe) Feed(buf []byte) consts.ProbingState {
6965
}
7066

7167
if !probe.IsActive() {
72-
c.log.Debugf("%s not active", probe.CharSetName())
7368
continue
7469
}
7570

@@ -110,12 +105,10 @@ func (c *CharSetGroupProbe) GetConfidence() float64 {
110105
}
111106

112107
if !probe.IsActive() {
113-
c.log.Debugf("%s not active", probe.CharSetName())
114108
continue
115109
}
116110

117111
conf := probe.GetConfidence()
118-
c.log.Debugf("%s %s confidence = %f", probe.CharSetName(), probe.Language(), conf)
119112
if bestConf < conf {
120113
bestConf = conf
121114
c.bestGuessProbe = probe

probe/euc_jp_probe.go

-5
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ package probe
33
import (
44
"github.com/wlynxg/chardet/cda"
55
"github.com/wlynxg/chardet/consts"
6-
"github.com/wlynxg/chardet/log"
7-
"go.uber.org/zap"
86
)
97

108
type EUCJPProbe struct {
119
MultiByteCharSetProbe
12-
log *zap.SugaredLogger
1310
contextAnalyzer cda.Analyzer
1411
}
1512

1613
func NewEUCJPProbe() *EUCJPProbe {
1714
ep := &EUCJPProbe{
18-
log: log.New("EUCJPProbe"),
1915
contextAnalyzer: cda.NewEUCJPContextAnalysis(),
2016
}
2117
ep.MultiByteCharSetProbe = NewMultiByteCharSetProbe(
@@ -40,7 +36,6 @@ loop:
4036
codingState := e.codingSM.NextState(b)
4137
switch codingState {
4238
case consts.ErrorMachineState:
43-
e.log.Debugf("%s %s prober hit error at byte %d", e.charsetName, e.language, i)
4439
e.state = consts.NotMeProbingState
4540
break loop
4641
case consts.ItsMeMachineState:

probe/mb_charset_probe.go

-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ package probe
33
import (
44
"github.com/wlynxg/chardet/cda"
55
"github.com/wlynxg/chardet/consts"
6-
"github.com/wlynxg/chardet/log"
7-
"go.uber.org/zap"
86
)
97

108
type MultiByteCharSetProbe struct {
119
CharSetProbe
1210

13-
log *zap.SugaredLogger
1411
charsetName, language string
1512
distributionAnalyzer cda.Analyzer
1613
codingSM *CodingStateMachine
@@ -21,7 +18,6 @@ func NewMultiByteCharSetProbe(charsetName, language string, filter consts.LangFi
2118
distributionAnalyzer cda.Analyzer, codingSM *CodingStateMachine) MultiByteCharSetProbe {
2219
return MultiByteCharSetProbe{
2320
CharSetProbe: NewCharSetProbe(filter),
24-
log: log.New("MultiByteCharSetProbe"),
2521
charsetName: charsetName,
2622
language: language,
2723
distributionAnalyzer: distributionAnalyzer,
@@ -51,7 +47,6 @@ loop:
5147
codingState := m.codingSM.NextState(buf[i])
5248
switch codingState {
5349
case consts.ErrorMachineState:
54-
m.log.Debugf("%s %s prober hit error at byte %d", m.charsetName, m.language, i)
5550
m.state = consts.NotMeProbingState
5651
break loop
5752
case consts.ItsMeMachineState:

probe/single_probe.go

-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package probe
22

33
import (
44
"github.com/wlynxg/chardet/consts"
5-
"github.com/wlynxg/chardet/log"
6-
"go.uber.org/zap"
75
)
86

97
type SingleByteCharSetModel struct {
@@ -22,7 +20,6 @@ type SingleByteCharSetProbe struct {
2220
SampleSize, SBEnoughRelThreshold int
2321
PositiveShortcutThreshold, NegativeShortcutThreshold float64
2422

25-
log *zap.SugaredLogger
2623
model *SingleByteCharSetModel
2724
reversed bool
2825
nameProbe Probe
@@ -41,7 +38,6 @@ func NewSingleByteCharSetProbe(model *SingleByteCharSetModel, reversed bool, nam
4138
SBEnoughRelThreshold: 1024, // 0.25 * SampleSize^2
4239
PositiveShortcutThreshold: 0.95,
4340
NegativeShortcutThreshold: 0.05,
44-
log: log.New("SingleByteCharSetProbe"),
4541
model: model,
4642
// TRUE if we need to reverse every pair in the model lookup
4743
reversed: reversed,
@@ -123,16 +119,12 @@ func (s *SingleByteCharSetProbe) Feed(buf []byte) consts.ProbingState {
123119
s.lastOrder = order
124120
}
125121

126-
charsetName := s.model.CharsetName
127122
if s.state == consts.DetectingProbingState {
128123
if s.totalSeqs > s.SBEnoughRelThreshold {
129124
confidence := s.GetConfidence()
130125
if confidence > s.PositiveShortcutThreshold {
131-
s.log.Debugf("%s confidence = %f, we have a winner", charsetName, confidence)
132126
s.state = consts.FoundItProbingState
133127
} else if confidence < s.NegativeShortcutThreshold {
134-
s.log.Debugf("%s confidence = %f, below negative shortcut threshhold %f",
135-
charsetName, confidence, s.NegativeShortcutThreshold)
136128
s.state = consts.NotMeProbingState
137129
}
138130
}

probe/sjis.go

-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ package probe
33
import (
44
"github.com/wlynxg/chardet/cda"
55
"github.com/wlynxg/chardet/consts"
6-
"github.com/wlynxg/chardet/log"
7-
"go.uber.org/zap"
86
)
97

108
type SJISProbe struct {
119
MultiByteCharSetProbe
1210

13-
log *zap.SugaredLogger
1411
state consts.ProbingState
1512
contextAnalyzer cda.Analyzer
1613
}
@@ -24,7 +21,6 @@ func NewSJISProbe() *SJISProbe {
2421
cda.NewSJISDistributionAnalysis(),
2522
NewCodingStateMachine(SjisSmModel()),
2623
),
27-
log: log.New("SJISProbe"),
2824
contextAnalyzer: cda.NewSJISContextAnalysis(),
2925
}
3026
}
@@ -46,7 +42,6 @@ loop:
4642
codingState := s.codingSM.NextState(buf[i])
4743
switch codingState {
4844
case consts.ErrorMachineState:
49-
s.log.Debugf("%s %s prober hit error at byte %d", s.charsetName, s.language, i)
5045
s.state = consts.NotMeProbingState
5146
break loop
5247
case consts.ItsMeMachineState:

util/util.go

-5
This file was deleted.

0 commit comments

Comments
 (0)