MCPcopy Create free account
hub / github.com/apache/impala / STLStringResizeUninitialized

Function STLStringResizeUninitialized

be/src/gutil/stl_util.h:269–290  ·  view source on GitHub ↗

Like str->resize(new_size), except any new characters added to "*str" as a result of resizing may be left uninitialized, rather than being filled with '0' bytes. Typically used when code is then going to overwrite the backing store of the string with known data.

Source from the content-addressed store, hash-verified

267// than being filled with '0' bytes. Typically used when code is then
268// going to overwrite the backing store of the string with known data.
269inline void STLStringResizeUninitialized(string* s, size_t new_size) {
270 if (sizeof(*s) == sizeof(InternalStringRepGCC4)) {
271 if (new_size > s->capacity()) {
272 s->reserve(new_size);
273 }
274 // The line below depends on the layout of 'string'. THIS IS
275 // NON-PORTABLE CODE. If our STL implementation changes, we will
276 // need to change this as well.
277 InternalStringRepGCC4* rep = reinterpret_cast<InternalStringRepGCC4*>(s);
278 assert(rep->_M_data == s->data());
279 assert(rep->_M_string_length == s->size());
280
281 // We have to null-terminate the string for c_str() to work properly.
282 // So we leave the actual contents of the string uninitialized, but
283 // we set the byte one past the new end of the string to '\0'
284 const_cast<char*>(s->data())[new_size] = '\0';
285 rep->_M_string_length = new_size;
286 } else {
287 // Slow path: have to reallocate stuff, or an unknown string rep
288 s->resize(new_size);
289 }
290}
291
292// Returns true if the string implementation supports a resize where
293// the new characters added to the string are left untouched.

Callers 8

STLAssignToStringFunction · 0.85
STLAppendToStringFunction · 0.85
SubstituteAndAppendFunction · 0.85
StrCatFunction · 0.85
StrCatNineOrMoreFunction · 0.85
StrAppendFunction · 0.85
EncodePODFunction · 0.85
EncodeVectorPODFunction · 0.85

Calls 5

reserveMethod · 0.80
resizeMethod · 0.80
capacityMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected