Skip to content

Commit

Permalink
filter2/mutate2/mutate3: fixed the speed problem! I was stupid. #172
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Nov 21, 2024
1 parent cb53cf8 commit d20aa89
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 112 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- [csvtk v0.31.1](https://github.com/shenwei356/csvtk/releases/tag/v0.31.1)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/csvtk/v0.31.1/total.svg)](https://github.com/shenwei356/csvtk/releases/tag/v0.31.1)
- `csvtk filter2/mutate2/mutate3`:
- fix the slow speed, I was stupid before. []#172](https://github.com/shenwei356/csvtk/issues/172)
- `csvtk csv2json`:
- further fix values with double quotes and new line symbols. [#291](https://github.com/shenwei356/csvtk/issues/291)
- [csvtk v0.31.0](https://github.com/shenwei356/csvtk/releases/tag/v0.31.0)
Expand Down
10 changes: 5 additions & 5 deletions csvtk/cmd/filter2.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ Custom functions:
fieldsUniq = UniqInts(record.Fields)

if !config.NoHeaderRow || record.IsHeaderRow { // do not replace head line
colnames2fileds = make(map[string][]int, len(record.All))
colnames2fileds = make(map[string][]int, len(record.Selected))

colnamesMap = make(map[string]*regexp.Regexp, len(record.All))
for i, col = range record.All {
colnamesMap = make(map[string]*regexp.Regexp, len(record.Selected))
for i, col = range record.Selected {
if _, ok = colnames2fileds[col]; !ok {
colnames2fileds[col] = []int{i + 1}
colnames2fileds[col] = []int{record.Fields[i]}
} else {
colnames2fileds[col] = append(colnames2fileds[col], i+1)
colnames2fileds[col] = append(colnames2fileds[col], record.Fields[i])
}

colnamesMap[col] = fuzzyField2Regexp(col)
Expand Down
10 changes: 5 additions & 5 deletions csvtk/cmd/mutate2.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ Custom functions:
fieldsUniq = UniqInts(record.Fields)

if !config.NoHeaderRow || record.IsHeaderRow { // do not replace head line
colnames2fileds = make(map[string][]int, len(record.All))
colnames2fileds = make(map[string][]int, len(record.Selected))

colnamesMap = make(map[string]*regexp.Regexp, len(record.All))
for i, col = range record.All {
colnamesMap = make(map[string]*regexp.Regexp, len(record.Selected))
for i, col = range record.Selected {
if _, ok = colnames2fileds[col]; !ok {
colnames2fileds[col] = []int{i + 1}
colnames2fileds[col] = []int{record.Fields[i]}
} else {
colnames2fileds[col] = append(colnames2fileds[col], i+1)
colnames2fileds[col] = append(colnames2fileds[col], record.Fields[i])
}

colnamesMap[col] = fuzzyField2Regexp(col)
Expand Down
10 changes: 5 additions & 5 deletions csvtk/cmd/mutate3.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ func doMutate3(config Config, opts mutate3Opts) {
fieldsUniq = UniqInts(record.Fields)

if !config.NoHeaderRow || record.IsHeaderRow { // do not replace head line
colnames2fileds = make(map[string][]int, len(record.All))
colnames2fileds = make(map[string][]int, len(record.Selected))

colnamesMap = make(map[string]*regexp.Regexp, len(record.All))
for i, col = range record.All {
colnamesMap = make(map[string]*regexp.Regexp, len(record.Selected))
for i, col = range record.Selected {
if _, ok = colnames2fileds[col]; !ok {
colnames2fileds[col] = []int{i + 1}
colnames2fileds[col] = []int{record.Fields[i]}
} else {
colnames2fileds[col] = append(colnames2fileds[col], i+1)
colnames2fileds[col] = append(colnames2fileds[col], record.Fields[i])
}

colnamesMap[col] = fuzzyField2Regexp(col)
Expand Down
Loading

0 comments on commit d20aa89

Please sign in to comment.