From: Ilan Pillemer Date: Thu, 21 Jul 2022 07:39:21 +0000 (+0100) Subject: strings.Builder instead of bytes.Buffer (#285) X-Git-Tag: v1.7.2~111 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=adf5320df4676326c2f2612c2168c2113a7e6540;p=fsnotify.git strings.Builder instead of bytes.Buffer (#285) --- diff --git a/fsnotify.go b/fsnotify.go index b474b52..3fbc792 100644 --- a/fsnotify.go +++ b/fsnotify.go @@ -9,9 +9,9 @@ package fsnotify import ( - "bytes" "errors" "fmt" + "strings" ) // Event represents a single file system notification. @@ -33,28 +33,28 @@ const ( ) func (op Op) String() string { - // Use a buffer for efficient string concatenation - var buffer bytes.Buffer + // Use a builder for efficient string concatenation + var builder strings.Builder if op&Create == Create { - buffer.WriteString("|CREATE") + builder.WriteString("|CREATE") } if op&Remove == Remove { - buffer.WriteString("|REMOVE") + builder.WriteString("|REMOVE") } if op&Write == Write { - buffer.WriteString("|WRITE") + builder.WriteString("|WRITE") } if op&Rename == Rename { - buffer.WriteString("|RENAME") + builder.WriteString("|RENAME") } if op&Chmod == Chmod { - buffer.WriteString("|CHMOD") + builder.WriteString("|CHMOD") } - if buffer.Len() == 0 { + if builder.Len() == 0 { return "" } - return buffer.String()[1:] // Strip leading pipe + return builder.String()[1:] // Strip leading pipe } // String returns a string representation of the event in the form