luci-app-mosdns/mosdns/patches/118-utils-update-BytesToStringUnsafe-remove-SplitLineReg.patch
2023-09-23 15:17:07 +08:00

40 lines
1.0 KiB
Diff

From 4c1a7967a9367a8cce2b37fa6c81de1b50b9fa42 Mon Sep 17 00:00:00 2001
From: Irine Sistiana <49315432+IrineSistiana@users.noreply.github.com>
Date: Thu, 21 Sep 2023 22:30:15 +0800
Subject: [PATCH 2/9] utils: update BytesToStringUnsafe, remove SplitLineReg
---
pkg/utils/strings.go | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/pkg/utils/strings.go b/pkg/utils/strings.go
index 632aadb..23471c2 100644
--- a/pkg/utils/strings.go
+++ b/pkg/utils/strings.go
@@ -20,21 +20,13 @@
package utils
import (
- "regexp"
"strings"
"unsafe"
)
// BytesToStringUnsafe converts bytes to string.
func BytesToStringUnsafe(b []byte) string {
- return *(*string)(unsafe.Pointer(&b))
-}
-
-var charBlockExpr = regexp.MustCompile("\\S+")
-
-// SplitLineReg extracts words from s by using regexp "\S+".
-func SplitLineReg(s string) []string {
- return charBlockExpr.FindAllString(s, -1)
+ return unsafe.String(unsafe.SliceData(b), len(b))
}
// RemoveComment removes comment after "symbol".
--
2.34.8