Commit Graph

7 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
eaedadbed0
replace strings.Split(N) for strings.Cut() or alternatives
Go 1.18 and up now provides a strings.Cut() which is better suited for
splitting key/value pairs (and similar constructs), and performs better:

```go
func BenchmarkSplit(b *testing.B) {
        b.ReportAllocs()
        data := []string{"12hello=world", "12hello=", "12=hello", "12hello"}
        for i := 0; i < b.N; i++ {
                for _, s := range data {
                        _ = strings.SplitN(s, "=", 2)[0]
                }
        }
}

func BenchmarkCut(b *testing.B) {
        b.ReportAllocs()
        data := []string{"12hello=world", "12hello=", "12=hello", "12hello"}
        for i := 0; i < b.N; i++ {
                for _, s := range data {
                        _, _, _ = strings.Cut(s, "=")
                }
        }
}
```

    BenchmarkSplit
    BenchmarkSplit-10            8244206               128.0 ns/op           128 B/op          4 allocs/op
    BenchmarkCut
    BenchmarkCut-10             54411998                21.80 ns/op            0 B/op          0 allocs/op

While looking at occurrences of `strings.Split()`, I also updated some for alternatives,
or added some constraints; for cases where an specific number of items is expected, I used `strings.SplitN()`
with a suitable limit. This prevents (theoretical) unlimited splits.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-07 10:02:25 +01:00
Eng Zer Jun
50da673592
refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-09-21 09:50:38 +08:00
Shiming Zhang
869375a413 Remove useless lines
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
2021-05-20 16:19:09 +08:00
Sebastiaan van Stijn
ad090e67e9
man: move ctr.1, containerd-config to section 8, and fix generation
I missed this in my previous change: the ctr man page is also
in Section 8, because it's considered an administrative tool,
and containerd-config is related to containerd so updating these
as well.

This commit also fixes naming of the generated files, which was
hard-coded to .1.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-04-03 12:32:52 +02:00
Eli Uriegas
036db34f37
build: Fix manpage generation
Seems to be that docs/man/ctr.1.md and docs/man/containerd.1.md were
removed in #3637 and were not updated correctly in the Makefile, leading
to build failures like:

    + make man

    make: *** No rule to make target `man/ctr.1', needed by `man'.  Stop.

Changes the gen-manpages command to be specific on which manpages are to
be generated.

Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
2019-10-08 18:22:23 +00:00
Eli Uriegas
2a636f8c34
gen-manpages: Create man directory if it does not exist
Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
2019-09-23 20:31:26 +00:00
Michael Crosby
5a656cacb4 Move manpage gen to separate binary
This moves the man page generation to a separate binary

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-09-12 14:19:00 -04:00