Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
ba7204a7
Commit
ba7204a7
authored
Apr 24, 2016
by
Robert
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3859 from rw/go-zero-alloc-strings
Go: Fix heap allocation when reading a string.
parents
a0d1161f
e8ac0f29
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
1 deletion
+7
-1
table.go
go/table.go
+2
-1
unsafe.go
go/unsafe.go
+5
-0
No files found.
go/table.go
View file @
ba7204a7
...
...
@@ -26,7 +26,8 @@ func (t *Table) Indirect(off UOffsetT) UOffsetT {
// String gets a string from data stored inside the flatbuffer.
func
(
t
*
Table
)
String
(
off
UOffsetT
)
string
{
return
string
(
t
.
ByteVector
(
off
))
b
:=
t
.
ByteVector
(
off
)
return
byteSliceToString
(
b
)
}
// ByteVector gets a byte slice from data stored inside the flatbuffer.
...
...
go/unsafe.go
View file @
ba7204a7
...
...
@@ -43,3 +43,8 @@ var (
// SizeVOffsetT is the byte size of an VOffsetT.
SizeVOffsetT
=
int
(
unsafe
.
Sizeof
(
VOffsetT
(
0
)))
)
// byteSliceToString converts a []byte to string without a heap allocation.
func
byteSliceToString
(
b
[]
byte
)
string
{
return
*
(
*
string
)(
unsafe
.
Pointer
(
&
b
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment