RESOLVED FIXED Bug 109218
Yarr: Use OwnPtr to make pattern/disjunction/character-class ownership clearer.
https://bugs.webkit.org/show_bug.cgi?id=109218
Summary Yarr: Use OwnPtr to make pattern/disjunction/character-class ownership clearer.
Andreas Kling
Reported 2013-02-07 12:38:09 PST
Yarr could use a bit more OwnPtrs to simplify object lifetime management. And while we're there, there are some easy memory wins in excessive Vector padding..
Attachments
Proposed patch (23.99 KB, patch)
2013-02-07 12:40 PST, Andreas Kling
benjamin: review+
Andreas Kling
Comment 1 2013-02-07 12:40:19 PST
Created attachment 187149 [details] Proposed patch
Benjamin Poulain
Comment 2 2013-02-12 00:39:14 PST
Comment on attachment 187149 [details] Proposed patch View in context: https://bugs.webkit.org/attachment.cgi?id=187149&action=review This looks great. The one thing I am not a big fan is the swap() of allParenthesesInfo. It now clears the input vectors which could be unexpected for the caller of BytecodePattern. I guess we cannot use C++ move syntax here because of Windows. Do we have any other way to specify the move semantic? > Source/JavaScriptCore/yarr/YarrInterpreter.cpp:1714 > + parenthesesDisjunction->terms.reserveInitialCapacity(endTerm - beginTerm + 1); I think I'd add a new variable for "beginTerm + 1". A +1 use twice out of nowhere could be an invitation for future disasters. > Source/JavaScriptCore/yarr/YarrPattern.cpp:501 > + return m_pattern.m_disjunctions.last().get(); This is fairly ugly. Keeping the pointer around could be an option. > Source/JavaScriptCore/yarr/YarrPattern.h:284 > + return m_alternatives.last().get(); Again, not a fan of this notation. I think it reads worse than keeping a pointer separately.
Andreas Kling
Comment 3 2013-02-15 10:18:29 PST
(In reply to comment #2) > (From update of attachment 187149 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=187149&action=review > > This looks great. > > The one thing I am not a big fan is the swap() of allParenthesesInfo. It now clears the input vectors which could be unexpected for the caller of BytecodePattern. > I guess we cannot use C++ move syntax here because of Windows. Do we have any other way to specify the move semantic? Right. I couldn't think of anything better. One idea would be changing the argument name to reflect the swapping behavior; e.g "parenthesesInfoToAdopt" or such. Do note that this swap() is not really a crucial part of the patch, I added it mostly to be symmetrical with the other swap() that was happening in the same function. It's also worth noting that BytecodePattern is only constructed in this fashion (at the moment): PassOwnPtr<BytecodePattern> byteCompile(YarrPattern& pattern, BumpPointerAllocator* allocator) { return ByteCompiler(pattern).compile(allocator); } ^and here, the vector getting moved/swapped is a member of the ByteCompiler class, so it is never really expected to survive compile(). Though I agree that it would be nice to be more future-proof. :/ > > Source/JavaScriptCore/yarr/YarrInterpreter.cpp:1714 > > + parenthesesDisjunction->terms.reserveInitialCapacity(endTerm - beginTerm + 1); > > I think I'd add a new variable for "beginTerm + 1". > A +1 use twice out of nowhere could be an invitation for future disasters. True, I'll fix that. > > Source/JavaScriptCore/yarr/YarrPattern.cpp:501 > > + return m_pattern.m_disjunctions.last().get(); > > This is fairly ugly. Keeping the pointer around could be an option. > > > Source/JavaScriptCore/yarr/YarrPattern.h:284 > > + return m_alternatives.last().get(); > > Again, not a fan of this notation. I think it reads worse than keeping a pointer separately. My past self disagrees with your ugly and impure ideas. My present self agrees with you. Will fix!
Andreas Kling
Comment 4 2013-02-15 10:58:18 PST
Darin Adler
Comment 5 2013-05-26 18:13:50 PDT
*** Bug 73778 has been marked as a duplicate of this bug. ***
Note You need to log in before you can comment on or make changes to this bug.