@@ -26,11 +26,11 @@ type Value interface {
26
26
27
27
// Fixed size primitive types are represented in TypedValue.N
28
28
// for performance.
29
+ func (StringValue ) assertValue () {}
29
30
func (BigintValue ) assertValue () {}
30
31
func (BigdecValue ) assertValue () {}
31
32
func (DataByteValue ) assertValue () {}
32
33
func (PointerValue ) assertValue () {}
33
- func (* StringValue ) assertValue () {}
34
34
func (* ArrayValue ) assertValue () {}
35
35
func (* SliceValue ) assertValue () {}
36
36
func (* StructValue ) assertValue () {}
@@ -50,7 +50,7 @@ const (
50
50
)
51
51
52
52
var (
53
- _ Value = & StringValue {}
53
+ _ Value = StringValue ( "" )
54
54
_ Value = BigintValue {}
55
55
_ Value = BigdecValue {}
56
56
_ Value = DataByteValue {}
72
72
// ----------------------------------------
73
73
// StringValue
74
74
75
- // StringValue represents a string.
76
- // Base is an *ArrayValue that holds
77
- // the string’s bytes, and isNewBase
78
- // is a flag set when the Base is
79
- // newly allocated.
80
- // If the Base is not newly allocated
81
- // at runtime, it can be considered as
82
- // reusing the original memory allocated
83
- // during preprocessing. In this case,
84
- // it does not count towards garbage
85
- // collection because it is not a new
86
- // allocation.
87
- type StringValue struct {
88
- isNewBase bool // if the underlying data is new allocated or not.
89
- Base * ArrayValue
90
- }
91
-
92
- func NewStringValue (s string ) * StringValue {
93
- bz := []byte (s )
94
- sv := & StringValue {
95
- Base : & ArrayValue {
96
- Data : bz ,
97
- },
98
- }
99
- return sv
100
- }
101
-
102
- func (sv StringValue ) MarshalAmino () (string , error ) {
103
- if sv .Base == nil {
104
- return "" , nil
105
- }
106
- return string (sv .Base .Data ), nil
107
- }
108
-
109
- func (sv * StringValue ) UnmarshalAmino (s string ) error {
110
- bz := []byte (s )
111
-
112
- sv .Base = & ArrayValue {
113
- Data : bz ,
114
- }
115
- sv .isNewBase = true
116
-
117
- return nil
118
- }
75
+ type StringValue string
119
76
120
77
// ----------------------------------------
121
78
// BigintValue
@@ -1211,7 +1168,7 @@ func (tv *TypedValue) GetBool() bool {
1211
1168
return * (* bool )(unsafe .Pointer (& tv .N ))
1212
1169
}
1213
1170
1214
- func (tv * TypedValue ) SetString (s * StringValue ) {
1171
+ func (tv * TypedValue ) SetString (s StringValue ) {
1215
1172
if debug {
1216
1173
if tv .T .Kind () != StringKind || isNative (tv .T ) {
1217
1174
panic (fmt .Sprintf (
@@ -1230,10 +1187,10 @@ func (tv *TypedValue) GetString() string {
1230
1187
tv .T .String ()))
1231
1188
}
1232
1189
}
1233
- if tv .V == nil || tv . V .( * StringValue ). Base == nil {
1190
+ if tv .V == nil {
1234
1191
return ""
1235
1192
}
1236
- return string (tv .V .(* StringValue ). Base . Data )
1193
+ return string (tv .V .(StringValue ))
1237
1194
}
1238
1195
1239
1196
func (tv * TypedValue ) SetInt (n int ) {
@@ -2153,8 +2110,8 @@ func (tv *TypedValue) GetLength() int {
2153
2110
}
2154
2111
}
2155
2112
switch cv := tv .V .(type ) {
2156
- case * StringValue :
2157
- return len (cv . Base . Data )
2113
+ case StringValue :
2114
+ return len (cv )
2158
2115
case * ArrayValue :
2159
2116
return cv .GetLength ()
2160
2117
case * SliceValue :
@@ -2719,7 +2676,7 @@ func typedRune(r rune) TypedValue {
2719
2676
// NOTE: does not allocate; used for panics.
2720
2677
func typedString (s string ) TypedValue {
2721
2678
tv := TypedValue {T : StringType }
2722
- tv .V = NewStringValue (s )
2679
+ tv .V = StringValue (s )
2723
2680
return tv
2724
2681
}
2725
2682
0 commit comments