X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/14957cd040308e3eeec43d26bae5d76da13fcd85..refs/heads/master:/yarr/YarrInterpreter.h diff --git a/yarr/YarrInterpreter.h b/yarr/YarrInterpreter.h index 78a8f34..e3dea24 100644 --- a/yarr/YarrInterpreter.h +++ b/yarr/YarrInterpreter.h @@ -27,8 +27,6 @@ #define YarrInterpreter_h #include "YarrPattern.h" -#include -#include namespace WTF { class BumpPointerAllocator; @@ -105,9 +103,9 @@ struct ByteTerm { unsigned frameLocation; bool m_capture : 1; bool m_invert : 1; - int inputPosition; + unsigned inputPosition; - ByteTerm(UChar ch, int inputPos, unsigned frameLocation, unsigned quantityCount, QuantifierType quantityType) + ByteTerm(UChar ch, int inputPos, unsigned frameLocation, Checked quantityCount, QuantifierType quantityType) : frameLocation(frameLocation) , m_capture(false) , m_invert(false) @@ -126,11 +124,11 @@ struct ByteTerm { atom.patternCharacter = ch; atom.quantityType = quantityType; - atom.quantityCount = quantityCount; + atom.quantityCount = quantityCount.unsafeGet(); inputPosition = inputPos; } - ByteTerm(UChar lo, UChar hi, int inputPos, unsigned frameLocation, unsigned quantityCount, QuantifierType quantityType) + ByteTerm(UChar lo, UChar hi, int inputPos, unsigned frameLocation, Checked quantityCount, QuantifierType quantityType) : frameLocation(frameLocation) , m_capture(false) , m_invert(false) @@ -150,7 +148,7 @@ struct ByteTerm { atom.casedCharacter.lo = lo; atom.casedCharacter.hi = hi; atom.quantityType = quantityType; - atom.quantityCount = quantityCount; + atom.quantityCount = quantityCount.unsafeGet(); inputPosition = inputPos; } @@ -204,17 +202,17 @@ struct ByteTerm { return term; } - static ByteTerm CheckInput(unsigned count) + static ByteTerm CheckInput(Checked count) { ByteTerm term(TypeCheckInput); - term.checkInputCount = count; + term.checkInputCount = count.unsafeGet(); return term; } - static ByteTerm UncheckInput(unsigned count) + static ByteTerm UncheckInput(Checked count) { ByteTerm term(TypeUncheckInput); - term.checkInputCount = count; + term.checkInputCount = count.unsafeGet(); return term; } @@ -337,44 +335,44 @@ public: struct BytecodePattern { WTF_MAKE_FAST_ALLOCATED; public: - BytecodePattern(PassOwnPtr body, Vector allParenthesesInfo, YarrPattern& pattern, BumpPointerAllocator* allocator) - : m_body(body) + BytecodePattern(std::unique_ptr body, Vector>& parenthesesInfoToAdopt, YarrPattern& pattern, BumpPointerAllocator* allocator) + : m_body(WTF::move(body)) , m_ignoreCase(pattern.m_ignoreCase) , m_multiline(pattern.m_multiline) , m_allocator(allocator) { + m_body->terms.shrinkToFit(); + newlineCharacterClass = pattern.newlineCharacterClass(); wordcharCharacterClass = pattern.wordcharCharacterClass(); - m_allParenthesesInfo.append(allParenthesesInfo); - m_userCharacterClasses.append(pattern.m_userCharacterClasses); - // 'Steal' the YarrPattern's CharacterClasses! We clear its - // array, so that it won't delete them on destruction. We'll - // take responsibility for that. - pattern.m_userCharacterClasses.clear(); - } + m_allParenthesesInfo.swap(parenthesesInfoToAdopt); + m_allParenthesesInfo.shrinkToFit(); - ~BytecodePattern() - { - deleteAllValues(m_allParenthesesInfo); - deleteAllValues(m_userCharacterClasses); + m_userCharacterClasses.swap(pattern.m_userCharacterClasses); + m_userCharacterClasses.shrinkToFit(); } - OwnPtr m_body; + std::unique_ptr m_body; bool m_ignoreCase; bool m_multiline; // Each BytecodePattern is associated with a RegExp, each RegExp is associated - // with a JSGlobalData. Cache a pointer to out JSGlobalData's m_regExpAllocator. + // with a VM. Cache a pointer to out VM's m_regExpAllocator. BumpPointerAllocator* m_allocator; CharacterClass* newlineCharacterClass; CharacterClass* wordcharCharacterClass; private: - Vector m_allParenthesesInfo; - Vector m_userCharacterClasses; + Vector> m_allParenthesesInfo; + Vector> m_userCharacterClasses; }; +JS_EXPORT_PRIVATE std::unique_ptr byteCompile(YarrPattern&, BumpPointerAllocator*); +JS_EXPORT_PRIVATE unsigned interpret(BytecodePattern*, const String& input, unsigned start, unsigned* output); +unsigned interpret(BytecodePattern*, const LChar* input, unsigned length, unsigned start, unsigned* output); +unsigned interpret(BytecodePattern*, const UChar* input, unsigned length, unsigned start, unsigned* output); + } } // namespace JSC::Yarr #endif // YarrInterpreter_h