• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 Google LLC.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SKSL_MODIFIERSPOOL
9 #define SKSL_MODIFIERSPOOL
10 
11 #include "include/private/SkSLModifiers.h"
12 
13 #include <unordered_set>
14 
15 namespace SkSL {
16 
17 /**
18  * Deduplicates Modifiers objects and stores them in a shared pool. Modifiers are fairly heavy, and
19  * tend to be reused a lot, so deduplication can be a significant win.
20  */
21 class ModifiersPool {
22 public:
add(const Modifiers & modifiers)23     const Modifiers* add(const Modifiers& modifiers) {
24         auto [iter, wasInserted] = fModifiersSet.insert(modifiers);
25         return &*iter;
26     }
27 
clear()28     void clear() {
29         fModifiersSet.clear();
30     }
31 
32 private:
33     std::unordered_set<Modifiers> fModifiersSet;
34 };
35 
36 } // namespace SkSL
37 
38 #endif
39