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

Unified Diff: cc/base/rtree.cc

Issue 2591533002: cc: Change RTree nodes container to be a vector (with reserve). (Closed)
Patch Set: compile fix 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
« no previous file with comments | « cc/base/rtree.h ('k') | cc/base/rtree_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/base/rtree.cc
diff --git a/cc/base/rtree.cc b/cc/base/rtree.cc
index f4658459f16e97939cd75cd4db2e3d4a2c30d336..1cb0f997cd089f7582a6de965d90b677c2d547b2 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.
+ 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);
« no previous file with comments | « cc/base/rtree.h ('k') | cc/base/rtree_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698