Skip to content

Commit

Permalink
perf: remove the log component
Browse files Browse the repository at this point in the history
  • Loading branch information
wlynxg committed Dec 16, 2024
1 parent e6d5d66 commit bc7f18a
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 66 deletions.
6 changes: 0 additions & 6 deletions detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 0 additions & 25 deletions log/log.go

This file was deleted.

7 changes: 0 additions & 7 deletions probe/charset_group_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -69,7 +65,6 @@ func (c *CharSetGroupProbe) Feed(buf []byte) consts.ProbingState {
}

if !probe.IsActive() {
c.log.Debugf("%s not active", probe.CharSetName())
continue
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions probe/euc_jp_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions probe/mb_charset_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 0 additions & 8 deletions probe/single_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package probe

import (
"github.com/wlynxg/chardet/consts"
"github.com/wlynxg/chardet/log"
"go.uber.org/zap"
)

type SingleByteCharSetModel struct {
Expand All @@ -22,7 +20,6 @@ type SingleByteCharSetProbe struct {
SampleSize, SBEnoughRelThreshold int
PositiveShortcutThreshold, NegativeShortcutThreshold float64

log *zap.SugaredLogger
model *SingleByteCharSetModel
reversed bool
nameProbe Probe
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
}
Expand Down
5 changes: 0 additions & 5 deletions probe/sjis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -24,7 +21,6 @@ func NewSJISProbe() *SJISProbe {
cda.NewSJISDistributionAnalysis(),
NewCodingStateMachine(SjisSmModel()),
),
log: log.New("SJISProbe"),
contextAnalyzer: cda.NewSJISContextAnalysis(),
}
}
Expand All @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions util/util.go

This file was deleted.

0 comments on commit bc7f18a

Please sign in to comment.