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

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: 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
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 traverse multiple RVAs. This is useful for RVA translation
21 // without extra storage. For example, we might have a stored list of RVA
22 // locations, and we want to traverse the matching RVA targets.
23 class RvaVisitor {
24 public:
25 virtual ~RvaVisitor();
26 virtual size_t Remaining() const = 0;
27 virtual const RVA& Get() const = 0;
28 virtual void Next() = 0;
29 };
30
31 LabelManager();
32
33 virtual ~LabelManager();
34
35 // Initializes |labels_| using RVAs from |rva_visitor|. Each distinct RVA from
36 // |rva_visitor| yields a Label with |rva_| assigned as the RVA, and |count_|
37 // assigned as the repeat.
38 void Read(RvaVisitor* rva_visitor);
39
40 // Removes |labels_| elements whose |count_| is less than |count_threshold|.
41 void RemoveUnderusedLabels(int count_threshold);
42
43 // Efficiently searches for a Label that targets |rva|. Returns the pointer to
44 // the stored Label instance if found, or null otherwise.
45 Label* Find(RVA rva);
46
47 // TODO(huangs): Move AssignRemainingIndexes() here.
48
49 protected:
50 // The main list of Label instances, sorted by the |rva_| member.
51 std::vector<Label> labels_;
52
53 private:
54 DISALLOW_COPY_AND_ASSIGN(LabelManager);
55 };
56
57 } // namespace courgette
58
59 #endif // COURGETTE_LABEL_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698