Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
106250a1
Commit
106250a1
authored
5 years ago
by
Hans Moog
Browse files
Options
Downloads
Patches
Plain Diff
Refactor: removed unused unsafeconvert package
parent
ae0d5f83
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/unsafeconvert/unsafeconvert.go
+0
-19
0 additions, 19 deletions
packages/unsafeconvert/unsafeconvert.go
packages/unsafeconvert/unsafeconvert_test.go
+0
-92
0 additions, 92 deletions
packages/unsafeconvert/unsafeconvert_test.go
with
0 additions
and
111 deletions
packages/unsafeconvert/unsafeconvert.go
deleted
100644 → 0
+
0
−
19
View file @
ae0d5f83
package
unsafeconvert
import
(
"unsafe"
)
// Converts a slice of bytes into a string without performing a copy.
// NOTE: This is an unsafe operation and may lead to problems if the bytes
// passed as argument are changed while the string is used. No checking whether
// bytes are valid UTF-8 data is performed.
func
BytesToString
(
bs
[]
byte
)
string
{
return
*
(
*
string
)(
unsafe
.
Pointer
(
&
bs
))
}
// Converts a string into a slice of bytes without performing a copy.
// NOTE: This is an unsafe operation and may lead to problems if the bytes are changed.
func
StringToBytes
(
s
string
)
[]
byte
{
return
*
(
*
[]
byte
)(
unsafe
.
Pointer
(
&
s
))
}
This diff is collapsed.
Click to expand it.
packages/unsafeconvert/unsafeconvert_test.go
deleted
100644 → 0
+
0
−
92
View file @
ae0d5f83
package
unsafeconvert
import
(
"bytes"
"strings"
"testing"
)
var
testStrings
=
[]
string
{
""
,
" "
,
"test"
,
"こんにちは、 世界"
,
strings
.
Repeat
(
" "
,
10
),
strings
.
Repeat
(
" "
,
100
),
strings
.
Repeat
(
" "
,
10000
),
strings
.
Repeat
(
" "
,
1000000
),
}
func
TestBytesToString
(
t
*
testing
.
T
)
{
for
_
,
expected
:=
range
testStrings
{
arg
:=
[]
byte
(
expected
)
actual
:=
BytesToString
(
arg
)
if
actual
!=
expected
{
t
.
Errorf
(
"BytesToString(%q) = %q but expected %q"
,
arg
,
actual
,
expected
)
}
}
}
func
TestStringToBytes
(
t
*
testing
.
T
)
{
for
_
,
arg
:=
range
testStrings
{
expected
:=
[]
byte
(
arg
)
actual
:=
StringToBytes
(
arg
)
if
!
bytes
.
Equal
(
actual
,
expected
)
{
t
.
Errorf
(
"Bytes(%q) = %q but expected %q"
,
arg
,
actual
,
expected
)
}
}
}
func
TestNil
(
t
*
testing
.
T
)
{
actual
:=
BytesToString
(
nil
)
expected
:=
""
if
actual
!=
expected
{
t
.
Errorf
(
"String(nil) = %q but expected %q"
,
actual
,
expected
)
}
}
func
createTestBytes
()
[][]
byte
{
result
:=
make
([][]
byte
,
len
(
testStrings
))
for
i
,
str
:=
range
testStrings
{
result
[
i
]
=
[]
byte
(
str
)
}
return
result
}
func
BenchmarkNativeBytesToString
(
b
*
testing
.
B
)
{
testBytes
:=
createTestBytes
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
_
,
bs
:=
range
testBytes
{
_
=
string
(
bs
)
}
}
}
func
BenchmarkUnsafeBytesToString
(
b
*
testing
.
B
)
{
testBytes
:=
createTestBytes
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
_
,
bs
:=
range
testBytes
{
_
=
BytesToString
(
bs
)
}
}
}
func
BenchmarkNativeStringToBytes
(
b
*
testing
.
B
)
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
_
,
str
:=
range
testStrings
{
_
=
[]
byte
(
str
)
}
}
}
func
BenchmarkUnsafeStringToBytes
(
b
*
testing
.
B
)
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
_
,
str
:=
range
testStrings
{
_
=
StringToBytes
(
str
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment