Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
94c2536e
Commit
94c2536e
authored
Nov 15, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
runtime: avoid allocation for make([]T, 0)
R=gri, iant, iant CC=golang-dev
https://golang.org/cl/5375093
parent
276473cd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
1 deletion
+8
-1
src/pkg/runtime/slice.c
src/pkg/runtime/slice.c
+8
-1
No files found.
src/pkg/runtime/slice.c
View file @
94c2536e
...
@@ -32,6 +32,11 @@ runtime·makeslice(SliceType *t, int64 len, int64 cap, Slice ret)
...
@@ -32,6 +32,11 @@ runtime·makeslice(SliceType *t, int64 len, int64 cap, Slice ret)
}
}
}
}
// Dummy word to use as base pointer for make([]T, 0).
// Since you cannot take the address of such a slice,
// you can't tell that they all have the same base pointer.
static
uintptr
zerobase
;
static
void
static
void
makeslice1
(
SliceType
*
t
,
int32
len
,
int32
cap
,
Slice
*
ret
)
makeslice1
(
SliceType
*
t
,
int32
len
,
int32
cap
,
Slice
*
ret
)
{
{
...
@@ -42,7 +47,9 @@ makeslice1(SliceType *t, int32 len, int32 cap, Slice *ret)
...
@@ -42,7 +47,9 @@ makeslice1(SliceType *t, int32 len, int32 cap, Slice *ret)
ret
->
len
=
len
;
ret
->
len
=
len
;
ret
->
cap
=
cap
;
ret
->
cap
=
cap
;
if
((
t
->
elem
->
kind
&
KindNoPointers
))
if
(
cap
==
0
)
ret
->
array
=
(
byte
*
)
&
zerobase
;
else
if
((
t
->
elem
->
kind
&
KindNoPointers
))
ret
->
array
=
runtime
·
mallocgc
(
size
,
FlagNoPointers
,
1
,
1
);
ret
->
array
=
runtime
·
mallocgc
(
size
,
FlagNoPointers
,
1
,
1
);
else
else
ret
->
array
=
runtime
·
mal
(
size
);
ret
->
array
=
runtime
·
mal
(
size
);
...
...
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