@@ -8,23 +8,23 @@ import (
88
99// Code object
1010type Code struct {
11- Argcount int32 // #arguments, except *args
12- Kwonlyargcount int32 // #keyword only arguments
13- Nlocals int32 // #local variables
14- Stacksize int32 // #entries needed for evaluation stack
15- Flags int32 // CO_..., see below
16- Code String // instruction opcodes
17- Consts Tuple // list (constants used)
18- Names Tuple // list of strings (names used)
19- Varnames Tuple // tuple of strings (local variable names)
20- Freevars Tuple // tuple of strings (free variable names)
21- Cellvars Tuple // tuple of strings (cell variable names)
11+ Argcount int32 // #arguments, except *args
12+ Kwonlyargcount int32 // #keyword only arguments
13+ Nlocals int32 // #local variables
14+ Stacksize int32 // #entries needed for evaluation stack
15+ Flags int32 // CO_..., see below
16+ Code string // instruction opcodes
17+ Consts Tuple // list (constants used)
18+ Names [] string // list of strings (names used)
19+ Varnames [] string // tuple of strings (local variable names)
20+ Freevars [] string // tuple of strings (free variable names)
21+ Cellvars [] string // tuple of strings (cell variable names)
2222 // The rest doesn't count for hash or comparisons
2323 Cell2arg * byte // Maps cell vars which are arguments.
24- Filename String // unicode (where it was loaded from)
25- Name String // unicode (name, for reference)
24+ Filename string // unicode (where it was loaded from)
25+ Name string // unicode (name, for reference)
2626 Firstlineno int32 // first source line number
27- Lnotab String // string (encoding addr<->lineno mapping) See Objects/lnotab_notes.txt for details.
27+ Lnotab string // string (encoding addr<->lineno mapping) See Objects/lnotab_notes.txt for details.
2828
2929 Weakreflist List // to support weakrefs to code objects
3030}
@@ -103,14 +103,32 @@ func NewCode(argcount int32, kwonlyargcount int32,
103103
104104 // Type assert the objects
105105 consts := consts_ .(Tuple )
106- names := names_ .(Tuple )
107- varnames := varnames_ .(Tuple )
108- freevars := freevars_ .(Tuple )
109- cellvars := cellvars_ .(Tuple )
110- name := name_ .(String )
111- filename := filename_ .(String )
112- lnotab := lnotab_ .(String )
113- code := code_ .(String )
106+ namesTuple := names_ .(Tuple )
107+ varnamesTuple := varnames_ .(Tuple )
108+ freevarsTuple := freevars_ .(Tuple )
109+ cellvarsTuple := cellvars_ .(Tuple )
110+ name := string (name_ .(String ))
111+ filename := string (filename_ .(String ))
112+ lnotab := string (lnotab_ .(String ))
113+ code := string (code_ .(String ))
114+
115+ // Convert Tuples to native []string for speed
116+ names := make ([]string , len (namesTuple ))
117+ for i := range namesTuple {
118+ names [i ] = string (namesTuple [i ].(String ))
119+ }
120+ varnames := make ([]string , len (varnamesTuple ))
121+ for i := range varnamesTuple {
122+ varnames [i ] = string (varnamesTuple [i ].(String ))
123+ }
124+ freevars := make ([]string , len (freevarsTuple ))
125+ for i := range freevarsTuple {
126+ freevars [i ] = string (freevarsTuple [i ].(String ))
127+ }
128+ cellvars := make ([]string , len (cellvarsTuple ))
129+ for i := range cellvarsTuple {
130+ cellvars [i ] = string (cellvarsTuple [i ].(String ))
131+ }
114132
115133 // Check argument types
116134 if argcount < 0 || kwonlyargcount < 0 || nlocals < 0 {
@@ -124,10 +142,10 @@ func NewCode(argcount int32, kwonlyargcount int32,
124142 // }
125143
126144 n_cellvars := len (cellvars )
127- intern_strings (names )
128- intern_strings (varnames )
129- intern_strings (freevars )
130- intern_strings (cellvars )
145+ intern_strings (namesTuple )
146+ intern_strings (varnamesTuple )
147+ intern_strings (freevarsTuple )
148+ intern_strings (cellvarsTuple )
131149 /* Intern selected string constants */
132150 for i := len (consts ) - 1 ; i >= 0 ; i -- {
133151 if v , ok := consts [i ].(String ); ok {
0 commit comments