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

Issue 15622005: Introduce LiteralSet (Closed)

Created:
7 years, 7 months ago by abarth-chromium
Modified:
6 years, 10 months ago
Reviewers:
eseidel
CC:
Stephen Chennney, blink-reviews, loislo+blink_chromium.org, eae+blinkwatch, yurys+blink_chromium.org, adamk+blink_chromium.org, jeez, eseidel, (unused - use chromium), Chris Evans
Visibility:
Public.

Description

Introduce LiteralSet This CL introduces WTF::LiteralSet, an implementation of a set based on a sorted table. TableSet is more memory efficient than HashSet for static sets because it doesn't allocate any memory. This CL deploys LiteralSet in ReplaceSelectionCommand.cpp and FormatBlockCommand.cpp. Future CLs will use LiteralSet in more locations.

Patch Set 1 #

Patch Set 2 : Use static tables #

Patch Set 3 : Cleaned #

Total comments: 10

Patch Set 4 : Address reviewer comments #

Patch Set 5 : Literal, Literal, Literal #

Unified diffs Side-by-side diffs Delta from patch set Stats (+141 lines, -97 lines) Patch
M Source/core/dom/QualifiedName.h View 1 2 3 4 2 chunks +23 lines, -4 lines 0 comments Download
M Source/core/editing/FormatBlockCommand.cpp View 1 2 3 4 1 chunk +29 lines, -25 lines 0 comments Download
M Source/core/editing/ReplaceSelectionCommand.cpp View 1 2 3 4 3 chunks +58 lines, -55 lines 0 comments Download
A + Source/wtf/LiteralSet.h View 1 2 3 4 1 chunk +30 lines, -13 lines 0 comments Download
M Source/wtf/wtf.gypi View 1 2 3 4 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 8 (0 generated)
abarth-chromium
7 years, 7 months ago (2013-05-22 00:12:32 UTC) #1
eseidel
Seems OK. It's not as polished as some of the other pieces of WTF, but ...
7 years, 7 months ago (2013-05-22 00:40:14 UTC) #2
abarth-chromium
On 2013/05/22 00:40:14, eseidel wrote: > Your most compelling argument is probably binary size. Do ...
7 years, 7 months ago (2013-05-22 00:54:15 UTC) #3
abarth-chromium
https://codereview.chromium.org/15622005/diff/6001/Source/core/editing/ReplaceSelectionCommand.cpp File Source/core/editing/ReplaceSelectionCommand.cpp (right): https://codereview.chromium.org/15622005/diff/6001/Source/core/editing/ReplaceSelectionCommand.cpp#newcode567 Source/core/editing/ReplaceSelectionCommand.cpp:567: static const QualifiedName* elementNames[] = { On 2013/05/22 00:40:14, ...
7 years, 7 months ago (2013-05-22 00:58:25 UTC) #4
eseidel
lgtm I think "literal" is more descriptive in this case than "static". Static implies to ...
7 years, 7 months ago (2013-05-22 19:44:46 UTC) #5
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/abarth@chromium.org/15622005/15006
7 years, 7 months ago (2013-05-22 19:53:23 UTC) #6
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/abarth@chromium.org/15622005/15006
7 years, 6 months ago (2013-06-05 07:43:40 UTC) #7
commit-bot: I haz the power
7 years, 6 months ago (2013-06-05 07:43:41 UTC) #8
Failed to apply patch for Source/wtf/LiteralSet.h:
While running patch -p1 --forward --force --no-backup-if-mismatch;
  A         Source/wtf/LiteralSet.h
  Copied Source/core/platform/Task.h -> Source/wtf/LiteralSet.h
  patching file Source/wtf/LiteralSet.h
  Hunk #1 FAILED at 28.
  1 out of 1 hunk FAILED -- saving rejects to file Source/wtf/LiteralSet.h.rej

Patch:   NR  Source/core/platform/Task.h->Source/wtf/LiteralSet.h
Index: Source/wtf/LiteralSet.h
diff --git a/Source/core/platform/Task.h b/Source/wtf/LiteralSet.h
similarity index 68%
copy from Source/core/platform/Task.h
copy to Source/wtf/LiteralSet.h
index
fe0270a8ec78113c954aa5a1fd5d2758d23a89eb..3dd52b40e582f65237c212de064cdb54e03dfe92
100644
--- a/Source/core/platform/Task.h
+++ b/Source/wtf/LiteralSet.h
@@ -28,30 +28,47 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef Task_h
-#define Task_h
+#ifndef WTF_LiteralSet_h
+#define WTF_LiteralSet_h
 
-#include "wtf/Functional.h"
-#include <public/WebThread.h>
+#include "wtf/NonCopyingSort.h"
 
-namespace WebCore {
+#include <algorithm>
 
-class Task : public WebKit::WebThread::Task {
+namespace WTF {
+
+template<typename T, typename Comparer>
+class LiteralSet {
 public:
-    explicit Task(const Closure& closure)
-        : m_closure(closure)
+    LiteralSet()
+        : m_values(0)
+        , m_size(0)
+    {
+    }
+
+    void init(T values[], size_t size)
     {
+        ASSERT(!isInitialized());
+        m_values = values;
+        m_size = size;
+        nonCopyingSort(m_values, m_values + m_size, Comparer::lessThan);
     }
 
-    virtual void run() OVERRIDE
+    bool contains(const T& value)
     {
-        m_closure();
+        ASSERT(isInitialized());
+        return std::binary_search(m_values, m_values + m_size, value,
Comparer::lessThan);
     }
 
+    bool isInitialized() { return !m_size; }
+
 private:
-    Closure m_closure;
+    T* m_values;
+    size_t m_size;
 };
 
-} // namespace WebCore
+} // namespace WTF
+
+using WTF::LiteralSet;
 
-#endif // Task_h
+#endif

Powered by Google App Engine
This is Rietveld 408576698