diff options
author | huangs <huangs@chromium.org> | 2015-12-07 17:27:46 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-08 01:28:46 +0000 |
commit | 7a2fea2555a8014c4bdcdbc1119b97f98e057248 (patch) | |
tree | c16e6282db8e51c0d6f37adde6b7effc14a20b09 /courgette/label_manager.h | |
parent | 56c43a002072a04abe25a77f400a1e3425ab8991 (diff) | |
download | chromium_src-7a2fea2555a8014c4bdcdbc1119b97f98e057248.zip chromium_src-7a2fea2555a8014c4bdcdbc1119b97f98e057248.tar.gz chromium_src-7a2fea2555a8014c4bdcdbc1119b97f98e057248.tar.bz2 |
[Courgette] Initial Implementation of LabelManager
This is part of the effort to reduce Courgette's peak memory. Main changes:
- Moving Label to image_utils.h, and change Label::count_ from int to int32.
- Adding utility class ConsecutiveRangeVisitor, with tests.
- Adding LabelManager, with tests.
The new code is not yet used in production.
Review URL: https://codereview.chromium.org/1491703003
Cr-Commit-Position: refs/heads/master@{#363688}
Diffstat (limited to 'courgette/label_manager.h')
-rw-r--r-- | courgette/label_manager.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/courgette/label_manager.h b/courgette/label_manager.h new file mode 100644 index 0000000..595e2e7 --- /dev/null +++ b/courgette/label_manager.h @@ -0,0 +1,64 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COURGETTE_LABEL_MANAGER_H_ +#define COURGETTE_LABEL_MANAGER_H_ + +#include <vector> + +#include "base/macros.h" +#include "courgette/image_utils.h" + +namespace courgette { + +// A container to store and manage Label instances. A key consideration is peak +// memory usage reduction. To this end we preallocate Label instances in bulk, +// and carefully control transient memory usage when initializing Labels. +class LabelManager { + public: + // An adaptor to sequentially traverse multiple RVAs. This is useful for RVA + // translation without extra storage. For example, we might have a stored list + // of RVA locations, but we want to traverse the matching RVA targets. + class RvaVisitor { + public: + virtual ~RvaVisitor(); + + // Returns the number of remaining RVAs to visit. + virtual size_t Remaining() const = 0; + + // Returns the current RVA. + virtual RVA Get() const = 0; + + // Advances to the next RVA. + virtual void Next() = 0; + }; + + LabelManager(); + virtual ~LabelManager(); + + // Initializes |labels_| using RVAs from |rva_visitor|. Each distinct RVA from + // |rva_visitor| yields a Label with |rva_| assigned as the RVA, and |count_| + // assigned as the repeat. + void Read(RvaVisitor* rva_visitor); + + // Removes |labels_| elements whose |count_| is less than |count_threshold|. + void RemoveUnderusedLabels(int32 count_threshold); + + // Efficiently searches for a Label that targets |rva|. Returns the pointer to + // the stored Label instance if found, or null otherwise. + Label* Find(RVA rva); + + // TODO(huangs): Move AssignRemainingIndexes() here. + + protected: + // The main list of Label instances, sorted by the |rva_| member. + std::vector<Label> labels_; + + private: + DISALLOW_COPY_AND_ASSIGN(LabelManager); +}; + +} // namespace courgette + +#endif // COURGETTE_LABEL_MANAGER_H_ |