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

Unified Diff: Source/wtf/LiteralSet.h

Issue 15622005: Introduce LiteralSet (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Literal, Literal, Literal Created 7 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/editing/ReplaceSelectionCommand.cpp ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « Source/core/editing/ReplaceSelectionCommand.cpp ('k') | Source/wtf/wtf.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698