@@ -33,7 +33,7 @@ void AssignRefCounted(StringPiece src, core::RefCounted* obj, string* out) {
33
33
out->assign (src.data (), src.size ());
34
34
}
35
35
36
- void EncodeStringList (const string * strings, int64 n, string* out) {
36
+ void EncodeStringList (const tstring * strings, int64 n, string* out) {
37
37
out->clear ();
38
38
for (int i = 0 ; i < n; ++i) {
39
39
core::PutVarint32 (out, strings[i].size ());
@@ -43,7 +43,7 @@ void EncodeStringList(const string* strings, int64 n, string* out) {
43
43
}
44
44
}
45
45
46
- bool DecodeStringList (const string& src, string * strings, int64 n) {
46
+ bool DecodeStringList (const string& src, tstring * strings, int64 n) {
47
47
std::vector<uint32> sizes (n);
48
48
StringPiece reader (src);
49
49
int64 tot = 0 ;
@@ -55,7 +55,7 @@ bool DecodeStringList(const string& src, string* strings, int64 n) {
55
55
return false ;
56
56
}
57
57
58
- string * data = strings;
58
+ tstring * data = strings;
59
59
for (int64 i = 0 ; i < n; ++i, ++data) {
60
60
auto size = sizes[i];
61
61
if (size > reader.size ()) {
@@ -144,7 +144,7 @@ void AssignRefCounted(StringPiece src, core::RefCounted* obj, Cord* out) {
144
144
cleanup);
145
145
}
146
146
147
- void EncodeStringList (const string * strings, int64 n, Cord* out) {
147
+ void EncodeStringList (const tstring * strings, int64 n, Cord* out) {
148
148
out->Clear ();
149
149
for (int i = 0 ; i < n; ++i) {
150
150
::strings::CordAppendVarint (strings[i].size(), out);
@@ -154,7 +154,7 @@ void EncodeStringList(const string* strings, int64 n, Cord* out) {
154
154
}
155
155
}
156
156
157
- bool DecodeStringList (const Cord& src, string * strings, int64 n) {
157
+ bool DecodeStringList (const Cord& src, tstring * strings, int64 n) {
158
158
std::vector<uint32> sizes (n);
159
159
CordReader reader (src);
160
160
int64 tot = 0 ;
@@ -165,14 +165,27 @@ bool DecodeStringList(const Cord& src, string* strings, int64 n) {
165
165
if (tot != reader.Available ()) {
166
166
return false ;
167
167
}
168
- string * data = strings;
168
+ tstring * data = strings;
169
169
for (int i = 0 ; i < n; ++i, ++data) {
170
170
auto size = sizes[i];
171
171
if (size > reader.Available ()) {
172
172
return false ;
173
173
}
174
+ #ifdef USE_TSTRING
175
+ // TODO(dero): Consider adding resize_uninitialized() to tstring once the
176
+ // tstring placeholder is replaced with the actual implementation.
177
+ //
178
+ // Currently, in the case of USE_TSTRING, the placeholder tstring class
179
+ // encapsulates a single std::string. We avoid using
180
+ // gtl::STLStringResizeUninitialized (and its associated header-include) in
181
+ // tstring.h as we have no intention in using it in the actual
182
+ // implementation. Thus, in the interim, we resort to resize().
183
+ data->resize (size);
184
+ reader.ReadN (size, data->data ());
185
+ #else // USE_TSTRING
174
186
gtl::STLStringResizeUninitialized (data, size);
175
187
reader.ReadN (size, gtl::string_as_array (data));
188
+ #endif // USE_TSTRING
176
189
}
177
190
return true ;
178
191
}
0 commit comments