* Switch to integer ranges in for loops
Signed-off-by: Stephen Kitt <steve@sk2.org>
* Switch to slices functions where appropriate
A number of utility functions can be replaced outright; since Miller
can technically be used as a library, these are deprecated rather than
removed. go:fix directives ensure that they can be replaced
automatically.
Signed-off-by: Stephen Kitt <steve@sk2.org>
* Switch to reflect.TypeFor
This is slightly more efficient than TypeOf when the type is known at
compile time.
Signed-off-by: Stephen Kitt <steve@sk2.org>
* Switch to strings.SplitSeq instead of strings.Split
SplitSeq results in fewer allocations.
Signed-off-by: Stephen Kitt <steve@sk2.org>
* Drop obsolete build directives
Signed-off-by: Stephen Kitt <steve@sk2.org>
* Use min/max instead of explicit comparisons
Signed-off-by: Stephen Kitt <steve@sk2.org>
* Append slices instead of looping
Signed-off-by: Stephen Kitt <steve@sk2.org>
---------
Signed-off-by: Stephen Kitt <steve@sk2.org>
* reader
* record writer
* pkg/output/record_writer_dcf.go
* test/input/test.dcf
* test/cases/io-dcf/
* pkg/cli/option_parse.go
* make fmt
* make dev
* docs and `make dev`
Both `(*Regexp).Match` and `(*Regexp).FindAllSubmatchIndex` have
string-based equivalents: `(*Regexp).MatchString` and
`(*Regexp).FindAllStringSubmatchIndex`. We should use the string version
to avoid unnecessary `[]byte` conversions.
Benchmark:
var regex = regexp.MustCompile("foo.*")
func BenchmarkMatch(b *testing.B) {
for i := 0; i < b.N; i++ {
if match := regex.Match([]byte("foo bar baz")); !match {
b.Fail()
}
}
}
func BenchmarkMatchString(b *testing.B) {
for i := 0; i < b.N; i++ {
if match := regex.MatchString("foo bar baz"); !match {
b.Fail()
}
}
}
func BenchmarkFindAllSubmatchIndex(b *testing.B) {
for i := 0; i < b.N; i++ {
if match := regex.FindAllSubmatchIndex([]byte("foo bar baz"), -1); len(match) == 0 {
b.Fail()
}
}
}
func BenchmarkFindAllStringSubmatchIndex(b *testing.B) {
for i := 0; i < b.N; i++ {
if match := regex.FindAllStringSubmatchIndex("foo bar baz", -1); len(match) == 0 {
b.Fail()
}
}
}
goos: linux
goarch: amd64
pkg: github.com/johnkerl/miller/pkg/lib
cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
BenchmarkMatch-16 2198350 517.5 ns/op 16 B/op 1 allocs/op
BenchmarkMatchString-16 3143605 371.5 ns/op 0 B/op 0 allocs/op
BenchmarkFindAllSubmatchIndex-16 921711 1199 ns/op 273 B/op 3 allocs/op
BenchmarkFindAllStringSubmatchIndex-16 1212321 981.0 ns/op 257 B/op 2 allocs/op
PASS
coverage: 0.0% of statements
ok github.com/johnkerl/miller/pkg/lib 6.576s
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.
[1]: https://golang.org/doc/go1.16#ioutil
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>