Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COURGETTE_LABEL_MANAGER_H_ | |
| 6 #define COURGETTE_LABEL_MANAGER_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "courgette/image_utils.h" | |
| 12 | |
| 13 namespace courgette { | |
| 14 | |
| 15 // A container to store and manage Label instances. A key consideration is peak | |
| 16 // memory usage reduction. To this end we preallocate Label instances in bulk, | |
| 17 // and carefully control transient memory usage when initializing Labels. | |
| 18 class LabelManager { | |
| 19 public: | |
| 20 // An adaptor to sequentially traverse multiple RVAs. This is useful for RVA | |
| 21 // translation without extra storage. For example, we might have a stored list | |
| 22 // of RVA locations, but we want to traverse the matching RVA targets. | |
| 23 class RvaVisitor { | |
| 24 public: | |
| 25 virtual ~RvaVisitor(); | |
| 26 | |
| 27 // Returns the number of remaining RVAs to visit. | |
| 28 virtual size_t Remaining() const = 0; | |
| 29 | |
| 30 // Returns the current RVA (by value). | |
|
grt (UTC plus 2)
2015/12/04 19:33:41
remove " (by value)" since it documents the obviou
huangs
2015/12/04 20:01:13
I figured this signals intent better, but for POD
| |
| 31 virtual RVA Get() const = 0; | |
| 32 | |
| 33 // Advances to the next RVA. | |
| 34 virtual void Next() = 0; | |
| 35 }; | |
| 36 | |
| 37 LabelManager(); | |
| 38 virtual ~LabelManager(); | |
| 39 | |
| 40 // Initializes |labels_| using RVAs from |rva_visitor|. Each distinct RVA from | |
| 41 // |rva_visitor| yields a Label with |rva_| assigned as the RVA, and |count_| | |
| 42 // assigned as the repeat. | |
| 43 void Read(RvaVisitor* rva_visitor); | |
| 44 | |
| 45 // Removes |labels_| elements whose |count_| is less than |count_threshold|. | |
| 46 void RemoveUnderusedLabels(int32 count_threshold); | |
| 47 | |
| 48 // Efficiently searches for a Label that targets |rva|. Returns the pointer to | |
| 49 // the stored Label instance if found, or null otherwise. | |
| 50 Label* Find(RVA rva); | |
| 51 | |
| 52 // TODO(huangs): Move AssignRemainingIndexes() here. | |
| 53 | |
| 54 protected: | |
| 55 // The main list of Label instances, sorted by the |rva_| member. | |
| 56 std::vector<Label> labels_; | |
| 57 | |
| 58 private: | |
| 59 DISALLOW_COPY_AND_ASSIGN(LabelManager); | |
| 60 }; | |
| 61 | |
| 62 } // namespace courgette | |
| 63 | |
| 64 #endif // COURGETTE_LABEL_MANAGER_H_ | |
| OLD | NEW |