File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -252,27 +252,38 @@ void ColumnString::Append(ColumnRef column) {
252
252
}
253
253
254
254
bool ColumnString::LoadBody (InputStream* input, size_t rows) {
255
- items_.clear ();
256
- blocks_.clear ();
255
+ if (rows == 0 ) {
256
+ items_.clear ();
257
+ blocks_.clear ();
258
+
259
+ return true ;
260
+ }
257
261
258
- items_.reserve (rows);
259
- Block * block = nullptr ;
262
+ decltype (items_) new_items;
263
+ decltype (blocks_) new_blocks;
264
+
265
+ new_items.reserve (rows);
266
+
267
+ // Suboptimzal if the first row string is >DEFAULT_BLOCK_SIZE, but that must be a very rare case.
268
+ Block * block = &new_blocks.emplace_back (DEFAULT_BLOCK_SIZE);
260
269
261
- // TODO(performance): unroll a loop to a first row (to get rid of `blocks_.size() == 0` check) and the rest.
262
270
for (size_t i = 0 ; i < rows; ++i) {
263
271
uint64_t len;
264
272
if (!WireFormat::ReadUInt64 (*input, &len))
265
273
return false ;
266
274
267
- if (blocks_. size () == 0 || len > block->GetAvailable ())
268
- block = &blocks_ .emplace_back (std::max<size_t >(DEFAULT_BLOCK_SIZE, len));
275
+ if (len > block->GetAvailable ())
276
+ block = &new_blocks .emplace_back (std::max<size_t >(DEFAULT_BLOCK_SIZE, len));
269
277
270
278
if (!WireFormat::ReadBytes (*input, block->GetCurrentWritePos (), len))
271
279
return false ;
272
280
273
- items_ .emplace_back (block->ConsumeTailAsStringViewUnsafe (len));
281
+ new_items .emplace_back (block->ConsumeTailAsStringViewUnsafe (len));
274
282
}
275
283
284
+ items_.swap (new_items);
285
+ blocks_.swap (new_blocks);
286
+
276
287
return true ;
277
288
}
278
289
You can’t perform that action at this time.
0 commit comments