RESOLVED FIXED Bug 101859
Use prefix form of increment / decrement operators in WTF String classes when possible
https://bugs.webkit.org/show_bug.cgi?id=101859
Summary Use prefix form of increment / decrement operators in WTF String classes when...
Chris Dumez
Reported 2012-11-11 04:34:12 PST
The WTF String classes implementation uses the postfix form of increment / decrement operators in several places where it is not needed. We should prefer using the prefix increment / decrement operators when possible as it is according to WebKit coding style and inherently more efficient.
Attachments
Patch (18.74 KB, patch)
2012-11-11 05:46 PST, Chris Dumez
no flags
Patch (18.71 KB, patch)
2012-11-11 09:49 PST, Chris Dumez
benjamin: review+
benjamin: commit-queue-
Patch for landing (18.73 KB, patch)
2012-11-12 12:43 PST, Chris Dumez
no flags
Chris Dumez
Comment 1 2012-11-11 05:46:18 PST
Andreas Kling
Comment 2 2012-11-11 09:23:17 PST
Comment on attachment 173500 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=173500&action=review > Source/WTF/ChangeLog:10 > + Use prefix form of increment / decrement operators whenever possible in > + WTF String classes as this is according to WebKit coding style and > + inherently more efficient. Why? Postfix increment/decrement does not generate any additional code for primitive types.
Chris Dumez
Comment 3 2012-11-11 09:42:34 PST
(In reply to comment #2) > (From update of attachment 173500 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=173500&action=review > > > Source/WTF/ChangeLog:10 > > + Use prefix form of increment / decrement operators whenever possible in > > + WTF String classes as this is according to WebKit coding style and > > + inherently more efficient. > > Why? Postfix increment/decrement does not generate any additional code for primitive types. Right, they are all primitive types so it would not affect performance. I'll remove the efficiency comment from the Changelog then. I still think it is good practice to use prefix operators whenever possible and WebKit seemed to follow this rule in most places I have seen.
Chris Dumez
Comment 4 2012-11-11 09:49:35 PST
Created attachment 173509 [details] Patch Remove the comment about efficiency from the Changelog since all changes relate to primitive types and it does not affect performance in this case as Kling rightfully mentioned. Is it right that we have such coding convention in WebKit though? This patch was basically a follow up to https://bugs.webkit.org/show_bug.cgi?id=101257#c22 : "Typically ++i in WebKit style."
Anders Carlsson
Comment 5 2012-11-11 16:12:36 PST
In general, we try not to do pure coding style cleanup patches. Instead, we make sure that any new code follows the style guidelines, and when changing a line of code it's fine to update it to follow the guidelines.
Benjamin Poulain
Comment 6 2012-11-12 12:28:19 PST
Comment on attachment 173509 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=173509&action=review Consistency is good and we are already in a period of coding style patches :) > Source/WTF/wtf/text/StringImpl.cpp:1863 > - terminatedString->m_length--; > + --terminatedString->m_length; I'd argue this one becomes harder to read with the change. I would prefer with parenthesis or with the old form.
Chris Dumez
Comment 7 2012-11-12 12:43:26 PST
Created attachment 173692 [details] Patch for landing Added parenthesis for "--(terminatedString->m_length);" to increase readability.
Anders Carlsson
Comment 8 2012-11-12 12:51:06 PST
(In reply to comment #6) > (From update of attachment 173509 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=173509&action=review > > Consistency is good and we are already in a period of coding style patches :) We are? That's unfortunate since they pollute svn blame for no good reason.
Benjamin Poulain
Comment 9 2012-11-13 16:49:55 PST
Comment on attachment 173692 [details] Patch for landing Ok, let's go for it. Rationale: This code cleaning is nice. It unify the style with what is ultimately very few changes. Blame is useless here anyway since most of that has be written before WTF was moved.
Anders Carlsson
Comment 10 2012-11-13 17:20:30 PST
(In reply to comment #9) > Blame is useless here anyway since most of that has be written before WTF was moved. Moving WTF out into a separate module did _not_ break svn blame.
Benjamin Poulain
Comment 11 2012-11-13 17:26:11 PST
(In reply to comment #10)) > > Blame is useless here anyway since most of that has be written before WTF was moved. > > Moving WTF out into a separate module did _not_ break svn blame. Oh, I did not know that. On GIT it certainly fucks things up, but it is very easy to live with it.
WebKit Review Bot
Comment 12 2012-11-13 17:28:15 PST
Comment on attachment 173692 [details] Patch for landing Clearing flags on attachment: 173692 Committed r134514: <http://trac.webkit.org/changeset/134514>
WebKit Review Bot
Comment 13 2012-11-13 17:28:20 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.