From bed4f33be8f18022e07e4f8c8b1526f2498affe0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 3 Feb 2023 09:51:54 +0530 Subject: [PATCH] Remove unused code --- .../utils/{unsafeutil_modern.go => unsafe.go} | 0 tools/utils/unsafeutil_legacy.go | 46 ------------------- 2 files changed, 46 deletions(-) rename tools/utils/{unsafeutil_modern.go => unsafe.go} (100%) delete mode 100644 tools/utils/unsafeutil_legacy.go diff --git a/tools/utils/unsafeutil_modern.go b/tools/utils/unsafe.go similarity index 100% rename from tools/utils/unsafeutil_modern.go rename to tools/utils/unsafe.go diff --git a/tools/utils/unsafeutil_legacy.go b/tools/utils/unsafeutil_legacy.go deleted file mode 100644 index 9ed6d1859..000000000 --- a/tools/utils/unsafeutil_legacy.go +++ /dev/null @@ -1,46 +0,0 @@ -// License: GPLv3 Copyright: 2022, Kovid Goyal, -//go:build !go1.20 - -package utils - -import ( - "unsafe" -) - -// stringHeader is the runtime representation of a string. -// It should be identical to reflect.StringHeader -type stringHeader struct { - data unsafe.Pointer - stringLen int -} - -// sliceHeader is the runtime representation of a slice. -// It should be identical to reflect.sliceHeader -type sliceHeader struct { - data unsafe.Pointer - sliceLen int - sliceCap int -} - -// Unsafely converts s into a byte slice. -// If you modify b, then s will also be modified. This violates the -// property that strings are immutable. -func UnsafeStringToBytes(s string) (b []byte) { - stringHeader := (*stringHeader)(unsafe.Pointer(&s)) - sliceHeader := (*sliceHeader)(unsafe.Pointer(&b)) - sliceHeader.data = stringHeader.data - sliceHeader.sliceLen = len(s) - sliceHeader.sliceCap = len(s) - return b -} - -// Unsafely converts b into a string. -// If you modify b, then s will also be modified. This violates the -// property that strings are immutable. -func UnsafeBytesToString(b []byte) (s string) { - sliceHeader := (*sliceHeader)(unsafe.Pointer(&b)) - stringHeader := (*stringHeader)(unsafe.Pointer(&s)) - stringHeader.data = sliceHeader.data - stringHeader.stringLen = len(b) - return s -}