]> go.fuhry.dev Git - fsnotify.git/commitdiff
strings.Builder instead of bytes.Buffer (#285)
authorIlan Pillemer <ilan.pillemer@gmail.com>
Thu, 21 Jul 2022 07:39:21 +0000 (08:39 +0100)
committerGitHub <noreply@github.com>
Thu, 21 Jul 2022 07:39:21 +0000 (09:39 +0200)
fsnotify.go

index b474b5263a55f29cd755ad1d22cb68c21c017f1e..3fbc792900da2e4d45ac271cd7ae7b3e321a8175 100644 (file)
@@ -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