@@ -123,14 +123,16 @@ func (w *Writer) fieldNeedsQuotesScalar(field string) bool {
123123}
124124
125125// fieldNeedsQuotesSIMD uses SIMD to detect special characters requiring quoting.
126+ // Uses cached broadcast values for fixed characters (quote, CR, NL) to avoid
127+ // repeated BroadcastInt8x32 calls.
126128func (w * Writer ) fieldNeedsQuotesSIMD (field string ) bool {
127129 data := unsafe .Slice (unsafe .StringData (field ), len (field ))
128130 int8Data := bytesToInt8Slice (data )
129131
130132 commaCmp := archsimd .BroadcastInt8x32 (int8 (w .Comma ))
131- newlineCmp := archsimd . BroadcastInt8x32 ( '\n' )
132- carriageReturnCmp := archsimd . BroadcastInt8x32 ( '\r' )
133- quoteCmp := archsimd . BroadcastInt8x32 ( '"' )
133+ newlineCmp := cachedNlCmp32
134+ carriageReturnCmp := cachedCrCmp32
135+ quoteCmp := cachedQuoteCmp32
134136
135137 // Process 32-byte chunks
136138 offset := 0
@@ -186,10 +188,11 @@ func (w *Writer) writeQuotedFieldScalar(field string) error {
186188}
187189
188190// writeQuotedFieldSIMD escapes quotes using SIMD to find quote positions.
191+ // Uses cached broadcast value for quote character to avoid repeated BroadcastInt8x32 calls.
189192func (w * Writer ) writeQuotedFieldSIMD (field string ) error {
190193 data := unsafe .Slice (unsafe .StringData (field ), len (field ))
191194 int8Data := bytesToInt8Slice (data )
192- quoteCmp := archsimd . BroadcastInt8x32 ( '"' )
195+ quoteCmp := cachedQuoteCmp32
193196
194197 offset := 0
195198 lastWritten := 0
0 commit comments