Yarr: if we're not using the output array, don't populate it!
https://bugs.webkit.org/show_bug.cgi?id=82519
Reviewed by Sam Weinig.
../JavaScriptCore:
Add a new variant of the match method to RegExp that returns a MatchResult,
and modify YarrJIT to be able to compile code that doesn't use an output vector.
This is a 3% progression on v8-regexp.
* JavaScriptCore.xcodeproj/project.pbxproj:
- Moved MatchResult into its own header.
* assembler/AbstractMacroAssembler.h:
- Added missing include.
* runtime/MatchResult.h: Added.
(MatchResult::MatchResult):
(MatchResult):
(MatchResult::failed):
(MatchResult::operator bool):
(MatchResult::empty):
- Moved MatchResult into its own header.
* runtime/RegExp.cpp:
(JSC::RegExp::compile):
(JSC::RegExp::compileIfNecessary):
(JSC::RegExp::match):
- Changed due to execute & representation changes.
(JSC::RegExp::compileMatchOnly):
(JSC::RegExp::compileIfNecessaryMatchOnly):
- Added helper to compile MatchOnly code.
(JSC::RegExp::invalidateCode):
(JSC::RegExp::matchCompareWithInterpreter):
(JSC::RegExp::printTraceData):
- Changed due representation changes.
* runtime/RegExp.h:
(RegExp):
(JSC::RegExp::hasCode):
- Made YarrCodeBlock a member.
* runtime/RegExpConstructor.h:
(RegExpConstructor):
(JSC::RegExpConstructor::performMatch):
- Added no-ovector form.
* runtime/RegExpMatchesArray.cpp:
(JSC::RegExpMatchesArray::reifyAllProperties):
- Match now takes a reference to ovector, not a pointer.
* runtime/RegExpObject.h:
(JSC):
- Moved MatchResult into its own header.
* runtime/StringPrototype.cpp:
(JSC::stringProtoFuncSplit):
- Match now takes a reference to ovector, not a pointer.
* testRegExp.cpp:
(testOneRegExp):
- Match now takes a reference to ovector, not a pointer.
* yarr/YarrJIT.cpp:
(Yarr):
(YarrGenerator):
(JSC::Yarr::YarrGenerator::initCallFrame):
(JSC::Yarr::YarrGenerator::removeCallFrame):
(JSC::Yarr::YarrGenerator::setSubpatternStart):
(JSC::Yarr::YarrGenerator::setSubpatternEnd):
(JSC::Yarr::YarrGenerator::clearSubpatternStart):
(JSC::Yarr::YarrGenerator::setMatchStart):
(JSC::Yarr::YarrGenerator::getMatchStart):
- Added helper functions to intermediate access to output.
(JSC::Yarr::YarrGenerator::generateDotStarEnclosure):
(JSC::Yarr::YarrGenerator::generate):
(JSC::Yarr::YarrGenerator::backtrack):
(JSC::Yarr::YarrGenerator::generateEnter):
(JSC::Yarr::YarrGenerator::compile):
- Changed to use the new helpers, only generate subpatterns if IncludeSubpatterns.
(JSC::Yarr::jitCompile):
- Needs to template of MatchOnly or IncludeSubpatterns.
* yarr/YarrJIT.h:
(YarrCodeBlock):
(JSC::Yarr::YarrCodeBlock::set8BitCode):
(JSC::Yarr::YarrCodeBlock::set16BitCode):
(JSC::Yarr::YarrCodeBlock::has8BitCodeMatchOnly):
(JSC::Yarr::YarrCodeBlock::has16BitCodeMatchOnly):
(JSC::Yarr::YarrCodeBlock::set8BitCodeMatchOnly):
(JSC::Yarr::YarrCodeBlock::set16BitCodeMatchOnly):
(JSC::Yarr::YarrCodeBlock::execute):
(JSC::Yarr::YarrCodeBlock::clear):
- Added a second set of CodeRefs, so that we can compile RexExps with/without subpattern matching.
../WebCore:
* ForwardingHeaders/runtime/MatchResult.h: Added.
* ForwardingHeaders/yarr/YarrJIT.h: Added.
- Added forwarding headers.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@112454 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/runtime/MatchResult.h b/Source/JavaScriptCore/runtime/MatchResult.h
new file mode 100644
index 0000000..d87c851
--- /dev/null
+++ b/Source/JavaScriptCore/runtime/MatchResult.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MatchResult_h
+#define MatchResult_h
+
+typedef uint64_t EncodedMatchResult;
+
+struct MatchResult {
+ ALWAYS_INLINE MatchResult(size_t start, size_t end)
+ : start(start)
+ , end(end)
+ {
+ }
+
+ explicit ALWAYS_INLINE MatchResult(EncodedMatchResult encoded)
+ {
+ union u {
+ uint64_t encoded;
+ struct s {
+ size_t start;
+ size_t end;
+ } split;
+ } value;
+ value.encoded = encoded;
+ start = value.split.start;
+ end = value.split.end;
+ }
+
+ ALWAYS_INLINE static MatchResult failed()
+ {
+ return MatchResult(WTF::notFound, 0);
+ }
+
+ ALWAYS_INLINE operator bool()
+ {
+ return start != WTF::notFound;
+ }
+
+ ALWAYS_INLINE bool empty()
+ {
+ return start == end;
+ }
+
+ size_t start;
+ size_t end;
+};
+
+#endif