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
64c3fe05
Commit
64c3fe05
authored
May 27, 2009
by
Ken Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
string([]int) conversion
R=r OCL=29466 CL=29466
parent
18890eeb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
1 deletion
+43
-1
builtin.c.boot
src/cmd/gc/builtin.c.boot
+1
-0
sys.go
src/cmd/gc/sys.go
+1
-0
walk.c
src/cmd/gc/walk.c
+19
-1
string.c
src/runtime/string.c
+22
-0
No files found.
src/cmd/gc/builtin.c.boot
View file @
64c3fe05
...
...
@@ -20,6 +20,7 @@ char *sysimport =
"func sys.indexstring (? string, ? int) (? uint8)\n"
"func sys.intstring (? int64) (? string)\n"
"func sys.arraystring (? []uint8) (? string)\n"
"func sys.arraystringi (? []int) (? string)\n"
"func sys.stringiter (? string, ? int) (? int)\n"
"func sys.stringiter2 (? string, ? int) (retk int, retv int)\n"
"func sys.ifaceI2E (iface any) (ret any)\n"
...
...
src/cmd/gc/sys.go
View file @
64c3fe05
...
...
@@ -29,6 +29,7 @@ func slicestring(string, int, int) string;
func
indexstring
(
string
,
int
)
byte
;
func
intstring
(
int64
)
string
;
func
arraystring
([]
byte
)
string
;
func
arraystringi
([]
int
)
string
;
func
stringiter
(
string
,
int
)
int
;
func
stringiter2
(
string
,
int
)
(
retk
int
,
retv
int
);
...
...
src/cmd/gc/walk.c
View file @
64c3fe05
...
...
@@ -1293,6 +1293,7 @@ walkconv(Node *n)
indir
(
n
,
stringop
(
n
,
Erv
));
return
;
}
// can convert []byte and *[10]byte
if
((
isptr
[
et
]
&&
isfixedarray
(
l
->
type
->
type
)
&&
istype
(
l
->
type
->
type
->
type
,
TUINT8
))
||
(
isslice
(
l
->
type
)
&&
istype
(
l
->
type
->
type
,
TUINT8
)))
{
...
...
@@ -1300,6 +1301,14 @@ walkconv(Node *n)
indir
(
n
,
stringop
(
n
,
Erv
));
return
;
}
// can convert []int and *[10]int
if
((
isptr
[
et
]
&&
isfixedarray
(
l
->
type
->
type
)
&&
istype
(
l
->
type
->
type
->
type
,
TINT
))
||
(
isslice
(
l
->
type
)
&&
istype
(
l
->
type
->
type
,
TINT
)))
{
n
->
op
=
OARRAY
;
indir
(
n
,
stringop
(
n
,
Erv
));
return
;
}
}
// convert dynamic to static generated by ONEW/OMAKE
...
...
@@ -2450,8 +2459,17 @@ stringop(Node *n, int top)
break
;
case
OARRAY
:
// arraystring([]byte) string;
r
=
n
->
left
;
if
(
r
->
type
!=
T
&&
r
->
type
->
type
!=
T
)
{
if
(
istype
(
r
->
type
->
type
,
TINT
)
||
istype
(
r
->
type
->
type
->
type
,
TINT
))
{
// arraystring([]byte) string;
on
=
syslook
(
"arraystringi"
,
0
);
r
=
nod
(
OCALL
,
on
,
r
);
break
;
}
}
// arraystring([]byte) string;
on
=
syslook
(
"arraystring"
,
0
);
r
=
nod
(
OCALL
,
on
,
r
);
break
;
...
...
src/runtime/string.c
View file @
64c3fe05
...
...
@@ -181,6 +181,28 @@ sys·arraystring(Array b, String s)
FLUSH
(
&
s
);
}
void
sys
·
arraystringi
(
Array
b
,
String
s
)
{
int32
siz
,
i
;
int32
*
a
;
byte
dum
[
8
];
a
=
(
int32
*
)
b
.
array
;
siz
=
0
;
for
(
i
=
0
;
i
<
b
.
nel
;
i
++
)
{
siz
+=
runetochar
(
dum
,
a
[
i
]);
}
s
=
gostringsize
(
siz
);
siz
=
0
;
for
(
i
=
0
;
i
<
b
.
nel
;
i
++
)
{
siz
+=
runetochar
(
s
.
str
+
siz
,
a
[
i
]);
}
FLUSH
(
&
s
);
}
enum
{
Runeself
=
0x80
,
...
...
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