Refactor ContentExtensionParser
[WebKit-https.git] / Source / WebCore / contentextensions / DFA.h
index e8e2f0b..289ae59 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef DFA_h
-#define DFA_h
+#pragma once
 
 #if ENABLE(CONTENT_EXTENSIONS)
 
 #include "ContentExtensionsDebugging.h"
 #include "DFANode.h"
+#include "PlatformExportMacros.h"
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -37,31 +37,51 @@ namespace WebCore {
 namespace ContentExtensions {
 
 // The DFA abstract a partial DFA graph in a compact form.
-class DFA {
-public:
-    DFA();
-    DFA(Vector<DFANode>&& nodes, unsigned rootIndex);
-    DFA(const DFA& dfa);
+struct WEBCORE_EXPORT DFA {
+    static DFA empty();
 
-    DFA& operator=(const DFA&);
-
-    unsigned root() const { return m_root; }
-    unsigned size() const { return m_nodes.size(); }
-    const DFANode& nodeAt(unsigned i) const { return m_nodes[i]; }
+    void shrinkToFit();
+    void minimize();
+    unsigned graphSize() const;
+    size_t memoryUsed() const;
 
 #if CONTENT_EXTENSIONS_STATE_MACHINE_DEBUGGING
     void debugPrintDot() const;
 #endif
 
-private:
-    Vector<DFANode> m_nodes;
-    unsigned m_root;
+    Vector<DFANode, 0, ContentExtensionsOverflowHandler> nodes;
+    Vector<uint64_t, 0, ContentExtensionsOverflowHandler> actions;
+    Vector<CharRange, 0, ContentExtensionsOverflowHandler> transitionRanges;
+    Vector<uint32_t, 0, ContentExtensionsOverflowHandler> transitionDestinations;
+    unsigned root { 0 };
 };
 
+inline const CharRange& DFANode::ConstRangeIterator::range() const
+{
+    return dfa.transitionRanges[position];
+}
+
+inline uint32_t DFANode::ConstRangeIterator::target() const
+{
+    return dfa.transitionDestinations[position];
+}
+
+inline const CharRange& DFANode::RangeIterator::range() const
+{
+    return dfa.transitionRanges[position];
 }
 
+inline uint32_t DFANode::RangeIterator::target() const
+{
+    return dfa.transitionDestinations[position];
+}
+
+inline void DFANode::RangeIterator::resetTarget(uint32_t newTarget)
+{
+    dfa.transitionDestinations[position] = newTarget;
+}
+
+} // namespace ContentExtensions
 } // namespace WebCore
 
 #endif // ENABLE(CONTENT_EXTENSIONS)
-
-#endif // DFA_h