Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
82c6f5e3
Commit
82c6f5e3
authored
Oct 26, 2010
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gc, runtime: copy([]byte, string)
R=ken2 CC=golang-dev
https://golang.org/cl/2741041
parent
e8bde0ec
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
2 deletions
+30
-2
builtin.c.boot
src/cmd/gc/builtin.c.boot
+1
-0
runtime.go
src/cmd/gc/runtime.go
+1
-0
typecheck.c
src/cmd/gc/typecheck.c
+6
-1
walk.c
src/cmd/gc/walk.c
+4
-1
slice.c
src/pkg/runtime/slice.c
+18
-0
No files found.
src/cmd/gc/builtin.c.boot
View file @
82c6f5e3
...
@@ -33,6 +33,7 @@ char *runtimeimport =
...
@@ -33,6 +33,7 @@ char *runtimeimport =
"func \"\".stringiter (? string, ? int) int\n"
"func \"\".stringiter (? string, ? int) int\n"
"func \"\".stringiter2 (? string, ? int) (retk int, retv int)\n"
"func \"\".stringiter2 (? string, ? int) (retk int, retv int)\n"
"func \"\".slicecopy (to any, fr any, wid uint32) int\n"
"func \"\".slicecopy (to any, fr any, wid uint32) int\n"
"func \"\".slicestringcopy (to any, fr any) int\n"
"func \"\".convI2E (elem any) any\n"
"func \"\".convI2E (elem any) any\n"
"func \"\".convI2I (typ *uint8, elem any) any\n"
"func \"\".convI2I (typ *uint8, elem any) any\n"
"func \"\".convT2E (typ *uint8, elem any) any\n"
"func \"\".convT2E (typ *uint8, elem any) any\n"
...
...
src/cmd/gc/runtime.go
View file @
82c6f5e3
...
@@ -48,6 +48,7 @@ func stringtosliceint(string) []int
...
@@ -48,6 +48,7 @@ func stringtosliceint(string) []int
func
stringiter
(
string
,
int
)
int
func
stringiter
(
string
,
int
)
int
func
stringiter2
(
string
,
int
)
(
retk
int
,
retv
int
)
func
stringiter2
(
string
,
int
)
(
retk
int
,
retv
int
)
func
slicecopy
(
to
any
,
fr
any
,
wid
uint32
)
int
func
slicecopy
(
to
any
,
fr
any
,
wid
uint32
)
int
func
slicestringcopy
(
to
any
,
fr
any
)
int
// interface conversions
// interface conversions
func
convI2E
(
elem
any
)
(
ret
any
)
func
convI2E
(
elem
any
)
(
ret
any
)
...
...
src/cmd/gc/typecheck.c
View file @
82c6f5e3
...
@@ -926,13 +926,18 @@ reswitch:
...
@@ -926,13 +926,18 @@ reswitch:
goto
error
;
goto
error
;
defaultlit
(
&
n
->
left
,
T
);
defaultlit
(
&
n
->
left
,
T
);
defaultlit
(
&
n
->
right
,
T
);
defaultlit
(
&
n
->
right
,
T
);
// copy([]byte, string)
if
(
isslice
(
n
->
left
->
type
)
&&
n
->
left
->
type
->
type
==
types
[
TUINT8
]
&&
n
->
right
->
type
->
etype
==
TSTRING
)
goto
ret
;
if
(
!
isslice
(
n
->
left
->
type
)
||
!
isslice
(
n
->
right
->
type
))
{
if
(
!
isslice
(
n
->
left
->
type
)
||
!
isslice
(
n
->
right
->
type
))
{
if
(
!
isslice
(
n
->
left
->
type
)
&&
!
isslice
(
n
->
right
->
type
))
if
(
!
isslice
(
n
->
left
->
type
)
&&
!
isslice
(
n
->
right
->
type
))
yyerror
(
"arguments to copy must be slices; have %lT, %lT"
,
n
->
left
->
type
,
n
->
right
->
type
);
yyerror
(
"arguments to copy must be slices; have %lT, %lT"
,
n
->
left
->
type
,
n
->
right
->
type
);
else
if
(
!
isslice
(
n
->
left
->
type
))
else
if
(
!
isslice
(
n
->
left
->
type
))
yyerror
(
"first argument to copy should be slice; have %lT"
,
n
->
left
->
type
);
yyerror
(
"first argument to copy should be slice; have %lT"
,
n
->
left
->
type
);
else
else
yyerror
(
"second argument to copy should be slice; have %lT"
,
n
->
right
->
type
);
yyerror
(
"second argument to copy should be slice
or string
; have %lT"
,
n
->
right
->
type
);
goto
error
;
goto
error
;
}
}
if
(
!
eqtype
(
n
->
left
->
type
->
type
,
n
->
right
->
type
->
type
))
{
if
(
!
eqtype
(
n
->
left
->
type
->
type
,
n
->
right
->
type
->
type
))
{
...
...
src/cmd/gc/walk.c
View file @
82c6f5e3
...
@@ -1261,7 +1261,10 @@ walkexpr(Node **np, NodeList **init)
...
@@ -1261,7 +1261,10 @@ walkexpr(Node **np, NodeList **init)
goto
ret
;
goto
ret
;
case
OCOPY
:
case
OCOPY
:
fn
=
syslook
(
"slicecopy"
,
1
);
if
(
n
->
right
->
type
->
etype
==
TSTRING
)
fn
=
syslook
(
"slicestringcopy"
,
1
);
else
fn
=
syslook
(
"slicecopy"
,
1
);
argtype
(
fn
,
n
->
left
->
type
);
argtype
(
fn
,
n
->
left
->
type
);
argtype
(
fn
,
n
->
right
->
type
);
argtype
(
fn
,
n
->
right
->
type
);
n
=
mkcall1
(
fn
,
n
->
type
,
init
,
n
=
mkcall1
(
fn
,
n
->
type
,
init
,
...
...
src/pkg/runtime/slice.c
View file @
82c6f5e3
...
@@ -217,6 +217,24 @@ out:
...
@@ -217,6 +217,24 @@ out:
}
}
}
}
void
·
slicestringcopy
(
Slice
to
,
String
fm
,
int32
ret
)
{
if
(
fm
.
len
==
0
||
to
.
len
==
0
)
{
ret
=
0
;
goto
out
;
}
ret
=
fm
.
len
;
if
(
to
.
len
<
ret
)
ret
=
to
.
len
;
memmove
(
to
.
array
,
fm
.
str
,
ret
);
out
:
FLUSH
(
&
ret
);
}
void
void
·
printslice
(
Slice
a
)
·
printslice
(
Slice
a
)
{
{
...
...
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