Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Unified Diff: content/child/blob_storage/blob_consolidation.cc

Issue 2448353002: [BlobAsync] Moving async handling into BlobStorageContext & quota out. (Closed)
Patch Set: comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/child/blob_storage/blob_consolidation.cc
diff --git a/content/child/blob_storage/blob_consolidation.cc b/content/child/blob_storage/blob_consolidation.cc
index ffcd12f089eefa839ef4ab3e0e1d5c0e07e5f60b..5b4152ee421003267188ecb024597697cd1cf868 100644
--- a/content/child/blob_storage/blob_consolidation.cc
+++ b/content/child/blob_storage/blob_consolidation.cc
@@ -126,47 +126,28 @@ ReadStatus BlobConsolidation::VisitMemory(size_t consolidated_item_index,
}
// We do a binary search to find the correct data to start with in the data
- // elements. This is slightly customized due to our unique storage and
- // constraints.
- size_t mid = 0;
- size_t offset_from_mid = consolidated_offset;
+ // elements.
+ const auto& offsets = item.offsets;
+ size_t item_index =
+ std::upper_bound(offsets.begin(), offsets.end(), consolidated_offset) -
+ offsets.begin();
+ size_t item_offset = base::checked_cast<size_t>(
+ item_index == 0 ? consolidated_offset
+ : consolidated_offset - offsets[item_index - 1]);
+
+ DCHECK_LT(item_offset, item.data[item_index].size());
+ // Read starting from 'item_index' and 'item_offset'.
size_t num_items = item.data.size();
- if (!item.offsets.empty()) {
- size_t low = 0;
- size_t high = num_items - 1;
- while (true) {
- mid = (high + low) / 2;
- // Note: we don't include the implicit '0' for the first item in offsets.
- size_t item_offset = (mid == 0 ? 0 : item.offsets[mid - 1]);
- offset_from_mid = consolidated_offset - item_offset;
- size_t next_item_offset = (mid + 1 == num_items ? 0 : item.offsets[mid]);
- if (item_offset == consolidated_offset) {
- // found exact match.
- break;
- } else if (item_offset > consolidated_offset) {
- high = mid - 1;
- } else if (mid + 1 == num_items ||
- next_item_offset > consolidated_offset) {
- // We are at the last item, or the next offset is greater than the one
- // we want, so the current item wins.
- break;
- } else {
- low = mid + 1;
- }
- }
- }
-
- DCHECK_LT(offset_from_mid, item.data[mid].size());
- // Read starting from 'mid' and 'offset_from_mid'.
for (size_t memory_read = 0;
- mid < num_items && memory_read < consolidated_size; mid++) {
- size_t read_size = std::min(item.data[mid].size() - offset_from_mid,
+ item_index < num_items && memory_read < consolidated_size;
+ item_index++) {
+ size_t read_size = std::min(item.data[item_index].size() - item_offset,
consolidated_size - memory_read);
bool continu =
- visitor.Run(item.data[mid].data() + offset_from_mid, read_size);
+ visitor.Run(item.data[item_index].data() + item_offset, read_size);
if (!continu)
return ReadStatus::CANCELLED_BY_VISITOR;
- offset_from_mid = 0;
+ item_offset = 0;
memory_read += read_size;
}
return ReadStatus::OK;
« no previous file with comments | « content/browser/service_worker/service_worker_url_request_job.cc ('k') | content/child/blob_storage/blob_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698