diff options
author | Mikhail Mazurskiy <mmazurskiy@gitlab.com> | 2022-06-22 10:26:41 +0300 |
---|---|---|
committer | Mikhail Mazurskiy <mmazurskiy@gitlab.com> | 2022-06-22 10:26:41 +0300 |
commit | 3593199ec13b9b96e714b85d05a06162c610315b (patch) | |
tree | d48cf95134d3999082a2c0e5f25149ca4343ffcf | |
parent | c31b039fa518dd329984c20f3a4961f9946490a4 (diff) |
Optimize ChompBytes() function
No need to allocate an intermediate string. Trim suffix first, then turn the result into a string.
-rw-r--r-- | internal/helper/text/chomp.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/internal/helper/text/chomp.go b/internal/helper/text/chomp.go index 6ce64cafa..bfc692a79 100644 --- a/internal/helper/text/chomp.go +++ b/internal/helper/text/chomp.go @@ -1,8 +1,10 @@ package text -import "strings" +import ( + "bytes" +) // ChompBytes converts b to a string with its trailing newline, if present, removed. func ChompBytes(b []byte) string { - return strings.TrimSuffix(string(b), "\n") + return string(bytes.TrimSuffix(b, []byte{'\n'})) } |