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

Side by Side Diff: courgette/label_manager.h

Issue 1491703003: [Courgette] Initial Implementation of LabelManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync. Created 5 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 unified diff | Download patch
« no previous file with comments | « courgette/image_utils.h ('k') | courgette/label_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 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_
OLDNEW
« no previous file with comments | « courgette/image_utils.h ('k') | courgette/label_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698