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

Unified Diff: cc/base/rtree.cc

Issue 2591533002: cc: Change RTree nodes container to be a vector (with reserve). (Closed)
Patch Set: cont: update Created 4 years 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: cc/base/rtree.cc
diff --git a/cc/base/rtree.cc b/cc/base/rtree.cc
index f4658459f16e97939cd75cd4db2e3d4a2c30d336..18caa713bfa5d724f07cd13e270c89e48cd52827 100644
--- a/cc/base/rtree.cc
+++ b/cc/base/rtree.cc
@@ -15,12 +15,16 @@
namespace cc {
-RTree::RTree() : num_data_elements_(0u), nodes_(sizeof(Node)) {}
+RTree::RTree() : num_data_elements_(0u) {}
RTree::~RTree() {}
RTree::Node* RTree::AllocateNodeAtLevel(int level) {
- Node& node = nodes_.AllocateAndConstruct<Node>();
+ // We don't allow reallocations, since that would invalidate references to
+ // existing nodes, so verify that capacity < size.
danakj 2016/12/19 22:20:50 u mean > ?
vmpstr 2016/12/19 22:51:27 Err yes, thx
+ DCHECK_GT(nodes_.capacity(), nodes_.size());
+ nodes_.emplace_back();
+ Node& node = nodes_.back();
node.num_children = 0;
node.level = level;
return &node;
@@ -36,17 +40,17 @@ RTree::Branch RTree::BuildRecursive(std::vector<Branch>* branches, int level) {
// We might sort our branches here, but we expect Blink gives us a reasonable
// x,y order. Skipping a call to sort (in Y) here resulted in a 17% win for
// recording with negligible difference in playback speed.
- int num_branches = static_cast<int>(branches->size() / MAX_CHILDREN);
- int remainder = static_cast<int>(branches->size() % MAX_CHILDREN);
+ int num_branches = static_cast<int>(branches->size() / kMaxChildren);
+ int remainder = static_cast<int>(branches->size() % kMaxChildren);
if (remainder > 0) {
++num_branches;
// If the remainder isn't enough to fill a node, we'll add fewer nodes to
// other branches.
- if (remainder >= MIN_CHILDREN)
+ if (remainder >= kMinChildren)
remainder = 0;
else
- remainder = MIN_CHILDREN - remainder;
+ remainder = kMinChildren - remainder;
}
int num_strips = static_cast<int>(std::ceil(std::sqrt(num_branches)));
@@ -58,15 +62,15 @@ RTree::Branch RTree::BuildRecursive(std::vector<Branch>* branches, int level) {
for (int i = 0; i < num_strips; ++i) {
// Might be worth sorting by X here too.
for (int j = 0; j < num_tiles && current_branch < branches->size(); ++j) {
- int increment_by = MAX_CHILDREN;
+ int increment_by = kMaxChildren;
if (remainder != 0) {
// if need be, omit some nodes to make up for remainder
- if (remainder <= MAX_CHILDREN - MIN_CHILDREN) {
+ if (remainder <= kMaxChildren - kMinChildren) {
increment_by -= remainder;
remainder = 0;
} else {
- increment_by = MIN_CHILDREN;
- remainder -= MAX_CHILDREN - MIN_CHILDREN;
+ increment_by = kMinChildren;
+ remainder -= kMaxChildren - kMinChildren;
}
}
Node* node = AllocateNodeAtLevel(level);

Powered by Google App Engine
This is Rietveld 408576698