aboutsummaryrefslogtreecommitdiff
path: root/difflines/unsafe.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-01-30 10:27:41 +0100
committerGravatar Runxi Yu2026-01-30 10:28:02 +0100
commit707342f0814da2fbd7c2b71ba1e973732900229f (patch)
treee0803c7c4ce6422a5c28b45573d4040dbac2d503 /difflines/unsafe.go
parentdiffbytes: Add package-level doc-comment (diff)
signatureNo signature
difflines: Rename from diffbytes v0.1.7
Diffstat (limited to 'difflines/unsafe.go')
-rw-r--r--difflines/unsafe.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/difflines/unsafe.go b/difflines/unsafe.go
new file mode 100644
index 00000000..6e7ac5fd
--- /dev/null
+++ b/difflines/unsafe.go
@@ -0,0 +1,17 @@
+package difflines
+
+import "unsafe"
+
+// // stringToBytes converts a string to a byte slice without copying the string.
+// // Memory is borrowed from the string.
+// // The resulting byte slice must not be modified in any form.
+// func stringToBytes(s string) (bytes []byte) {
+// return unsafe.Slice(unsafe.StringData(s), len(s)) //#nosec G103
+// }
+
+// bytesToString converts a byte slice to a string without copying the bytes.
+// Memory is borrowed from the byte slice.
+// The source byte slice must not be modified.
+func bytesToString(b []byte) string {
+ return unsafe.String(unsafe.SliceData(b), len(b)) //#nosec G103
+}