Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-flatbuffers
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-flatbuffers
Commits
e8ac0f29
Commit
e8ac0f29
authored
8 years ago
by
rw
Browse files
Options
Downloads
Patches
Plain Diff
Fix heap allocation when reading a string.
parent
a0d1161f
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
go/table.go
+2
-1
2 additions, 1 deletion
go/table.go
go/unsafe.go
+5
-0
5 additions, 0 deletions
go/unsafe.go
with
7 additions
and
1 deletion
go/table.go
+
2
−
1
View file @
e8ac0f29
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
go/unsafe.go
+
5
−
0
View file @
e8ac0f29
...
...
@@ -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
))
}
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