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. | |
31 virtual const RVA& Get() const = 0; | |
grt (UTC plus 2)
2015/12/03 15:19:09
an RVA is a 32-bit int, so treat it as a value typ
huangs
2015/12/03 19:29:06
Done.
| |
32 | |
33 // Advances to the next RVA. | |
34 virtual void Next() = 0; | |
35 }; | |
36 | |
37 LabelManager(); | |
38 | |
grt (UTC plus 2)
2015/12/03 15:19:09
omit this newline
huangs
2015/12/03 19:29:06
Done.
| |
39 virtual ~LabelManager(); | |
40 | |
41 // Initializes |labels_| using RVAs from |rva_visitor|. Each distinct RVA from | |
42 // |rva_visitor| yields a Label with |rva_| assigned as the RVA, and |count_| | |
43 // assigned as the repeat. | |
44 void Read(RvaVisitor* rva_visitor); | |
grt (UTC plus 2)
2015/12/03 15:19:09
it's hard to review this without seeing the consum
huangs
2015/12/03 19:29:06
The plan is that RvaVisitor will be specialized ov
| |
45 | |
46 // Removes |labels_| elements whose |count_| is less than |count_threshold|. | |
47 void RemoveUnderusedLabels(int count_threshold); | |
48 | |
49 // Efficiently searches for a Label that targets |rva|. Returns the pointer to | |
50 // the stored Label instance if found, or null otherwise. | |
51 Label* Find(RVA rva); | |
52 | |
53 // TODO(huangs): Move AssignRemainingIndexes() here. | |
54 | |
55 protected: | |
56 // The main list of Label instances, sorted by the |rva_| member. | |
57 std::vector<Label> labels_; | |
58 | |
59 private: | |
60 DISALLOW_COPY_AND_ASSIGN(LabelManager); | |
61 }; | |
62 | |
63 } // namespace courgette | |
64 | |
65 #endif // COURGETTE_LABEL_MANAGER_H_ | |
OLD | NEW |