From bc7f18a684362dd91851cf9c638f6d38a6593fa3 Mon Sep 17 00:00:00 2001 From: wlynxg Date: Mon, 16 Dec 2024 10:40:12 +0800 Subject: [PATCH] perf: remove the log component --- detector.go | 6 ------ log/log.go | 25 ------------------------- probe/charset_group_probe.go | 7 ------- probe/euc_jp_probe.go | 5 ----- probe/mb_charset_probe.go | 5 ----- probe/single_probe.go | 8 -------- probe/sjis.go | 5 ----- util/util.go | 5 ----- 8 files changed, 66 deletions(-) delete mode 100644 log/log.go delete mode 100644 util/util.go diff --git a/detector.go b/detector.go index 6e5751d..fe344e1 100644 --- a/detector.go +++ b/detector.go @@ -4,9 +4,7 @@ import ( "bytes" "github.com/wlynxg/chardet/consts" - "github.com/wlynxg/chardet/log" "github.com/wlynxg/chardet/probe" - "go.uber.org/zap" ) // Result represents the character encoding detection result @@ -26,8 +24,6 @@ type UniversalDetector struct { // IsoWinMap maps ISO encodings to Windows encodings IsoWinMap map[string]string - log *zap.SugaredLogger - // done indicates if detection is complete done bool // gotData indicates if any data has been processed @@ -70,7 +66,6 @@ func NewUniversalDetector(filter consts.LangFilter) *UniversalDetector { consts.ISO885913: consts.Windows1257, }, - log: log.New("UniversalDetector"), inputState: consts.PureAsciiInputState, lastChars: []byte{}, filter: filter, @@ -241,7 +236,6 @@ func (u *UniversalDetector) GetResult() Result { switch { case !u.gotData: - u.log.Debug("no data received!") case u.inputState == consts.PureAsciiInputState: u.result = Result{ Encoding: consts.Ascii, diff --git a/log/log.go b/log/log.go deleted file mode 100644 index 329f075..0000000 --- a/log/log.go +++ /dev/null @@ -1,25 +0,0 @@ -package log - -import ( - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -var ( - logLevel = zapcore.InfoLevel -) - -func New(name string) *zap.SugaredLogger { - cfg := zap.NewDevelopmentConfig() - cfg.Level.SetLevel(logLevel) - development, _ := cfg.Build() - return development.Sugar().Named(name) -} - -func SetLogLevel(level string) { - parseLevel, err := zapcore.ParseLevel(level) - if err != nil { - return - } - logLevel = parseLevel -} diff --git a/probe/charset_group_probe.go b/probe/charset_group_probe.go index 67186b1..1b8d94a 100644 --- a/probe/charset_group_probe.go +++ b/probe/charset_group_probe.go @@ -2,14 +2,11 @@ package probe import ( "github.com/wlynxg/chardet/consts" - "github.com/wlynxg/chardet/log" - "go.uber.org/zap" ) type CharSetGroupProbe struct { CharSetProbe - log *zap.SugaredLogger filter consts.LangFilter activeNum int bestGuessProbe Probe @@ -19,7 +16,6 @@ type CharSetGroupProbe struct { func NewCharSetGroupProbe(filter consts.LangFilter, probes []Probe) CharSetGroupProbe { p := CharSetGroupProbe{ CharSetProbe: NewCharSetProbe(filter), - log: log.New("CharSetGroupProbe"), filter: filter, activeNum: 0, bestGuessProbe: nil, @@ -69,7 +65,6 @@ func (c *CharSetGroupProbe) Feed(buf []byte) consts.ProbingState { } if !probe.IsActive() { - c.log.Debugf("%s not active", probe.CharSetName()) continue } @@ -110,12 +105,10 @@ func (c *CharSetGroupProbe) GetConfidence() float64 { } if !probe.IsActive() { - c.log.Debugf("%s not active", probe.CharSetName()) continue } conf := probe.GetConfidence() - c.log.Debugf("%s %s confidence = %f", probe.CharSetName(), probe.Language(), conf) if bestConf < conf { bestConf = conf c.bestGuessProbe = probe diff --git a/probe/euc_jp_probe.go b/probe/euc_jp_probe.go index 95aa0f6..540ab45 100644 --- a/probe/euc_jp_probe.go +++ b/probe/euc_jp_probe.go @@ -3,19 +3,15 @@ package probe import ( "github.com/wlynxg/chardet/cda" "github.com/wlynxg/chardet/consts" - "github.com/wlynxg/chardet/log" - "go.uber.org/zap" ) type EUCJPProbe struct { MultiByteCharSetProbe - log *zap.SugaredLogger contextAnalyzer cda.Analyzer } func NewEUCJPProbe() *EUCJPProbe { ep := &EUCJPProbe{ - log: log.New("EUCJPProbe"), contextAnalyzer: cda.NewEUCJPContextAnalysis(), } ep.MultiByteCharSetProbe = NewMultiByteCharSetProbe( @@ -40,7 +36,6 @@ loop: codingState := e.codingSM.NextState(b) switch codingState { case consts.ErrorMachineState: - e.log.Debugf("%s %s prober hit error at byte %d", e.charsetName, e.language, i) e.state = consts.NotMeProbingState break loop case consts.ItsMeMachineState: diff --git a/probe/mb_charset_probe.go b/probe/mb_charset_probe.go index b9d279c..2bb236c 100644 --- a/probe/mb_charset_probe.go +++ b/probe/mb_charset_probe.go @@ -3,14 +3,11 @@ package probe import ( "github.com/wlynxg/chardet/cda" "github.com/wlynxg/chardet/consts" - "github.com/wlynxg/chardet/log" - "go.uber.org/zap" ) type MultiByteCharSetProbe struct { CharSetProbe - log *zap.SugaredLogger charsetName, language string distributionAnalyzer cda.Analyzer codingSM *CodingStateMachine @@ -21,7 +18,6 @@ func NewMultiByteCharSetProbe(charsetName, language string, filter consts.LangFi distributionAnalyzer cda.Analyzer, codingSM *CodingStateMachine) MultiByteCharSetProbe { return MultiByteCharSetProbe{ CharSetProbe: NewCharSetProbe(filter), - log: log.New("MultiByteCharSetProbe"), charsetName: charsetName, language: language, distributionAnalyzer: distributionAnalyzer, @@ -51,7 +47,6 @@ loop: codingState := m.codingSM.NextState(buf[i]) switch codingState { case consts.ErrorMachineState: - m.log.Debugf("%s %s prober hit error at byte %d", m.charsetName, m.language, i) m.state = consts.NotMeProbingState break loop case consts.ItsMeMachineState: diff --git a/probe/single_probe.go b/probe/single_probe.go index cca361e..47cf40f 100644 --- a/probe/single_probe.go +++ b/probe/single_probe.go @@ -2,8 +2,6 @@ package probe import ( "github.com/wlynxg/chardet/consts" - "github.com/wlynxg/chardet/log" - "go.uber.org/zap" ) type SingleByteCharSetModel struct { @@ -22,7 +20,6 @@ type SingleByteCharSetProbe struct { SampleSize, SBEnoughRelThreshold int PositiveShortcutThreshold, NegativeShortcutThreshold float64 - log *zap.SugaredLogger model *SingleByteCharSetModel reversed bool nameProbe Probe @@ -41,7 +38,6 @@ func NewSingleByteCharSetProbe(model *SingleByteCharSetModel, reversed bool, nam SBEnoughRelThreshold: 1024, // 0.25 * SampleSize^2 PositiveShortcutThreshold: 0.95, NegativeShortcutThreshold: 0.05, - log: log.New("SingleByteCharSetProbe"), model: model, // TRUE if we need to reverse every pair in the model lookup reversed: reversed, @@ -123,16 +119,12 @@ func (s *SingleByteCharSetProbe) Feed(buf []byte) consts.ProbingState { s.lastOrder = order } - charsetName := s.model.CharsetName if s.state == consts.DetectingProbingState { if s.totalSeqs > s.SBEnoughRelThreshold { confidence := s.GetConfidence() if confidence > s.PositiveShortcutThreshold { - s.log.Debugf("%s confidence = %f, we have a winner", charsetName, confidence) s.state = consts.FoundItProbingState } else if confidence < s.NegativeShortcutThreshold { - s.log.Debugf("%s confidence = %f, below negative shortcut threshhold %f", - charsetName, confidence, s.NegativeShortcutThreshold) s.state = consts.NotMeProbingState } } diff --git a/probe/sjis.go b/probe/sjis.go index 103bf35..127b988 100644 --- a/probe/sjis.go +++ b/probe/sjis.go @@ -3,14 +3,11 @@ package probe import ( "github.com/wlynxg/chardet/cda" "github.com/wlynxg/chardet/consts" - "github.com/wlynxg/chardet/log" - "go.uber.org/zap" ) type SJISProbe struct { MultiByteCharSetProbe - log *zap.SugaredLogger state consts.ProbingState contextAnalyzer cda.Analyzer } @@ -24,7 +21,6 @@ func NewSJISProbe() *SJISProbe { cda.NewSJISDistributionAnalysis(), NewCodingStateMachine(SjisSmModel()), ), - log: log.New("SJISProbe"), contextAnalyzer: cda.NewSJISContextAnalysis(), } } @@ -46,7 +42,6 @@ loop: codingState := s.codingSM.NextState(buf[i]) switch codingState { case consts.ErrorMachineState: - s.log.Debugf("%s %s prober hit error at byte %d", s.charsetName, s.language, i) s.state = consts.NotMeProbingState break loop case consts.ItsMeMachineState: diff --git a/util/util.go b/util/util.go deleted file mode 100644 index 766f330..0000000 --- a/util/util.go +++ /dev/null @@ -1,5 +0,0 @@ -package util - -func IsAlpha(b byte) bool { - return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') -}