RESOLVED FIXED 192710
clang-tidy: Fix unnecessary copy of AtomicString each time one is logged
https://bugs.webkit.org/show_bug.cgi?id=192710
Summary clang-tidy: Fix unnecessary copy of AtomicString each time one is logged
David Kilzer (:ddkilzer)
Reported 2018-12-14 12:51:16 PST
Running `clang-tidy -header-filter=.* -checks='-*,performance-*,-performance-noexcept-*' ...` on WebCore source files found this unnecessary object copy: $BUILD_DIR/Release/usr/local/include/wtf/Logger.h:47:173: warning: the parameter 'argument' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] template<typename U = T> static typename std::enable_if<std::is_same<typename std::remove_reference<U>::type, AtomicString>::value, String>::type toString(AtomicString argument) { return argument.string(); } ^ const &
Attachments
Patch v1 (2.47 KB, patch)
2018-12-14 12:58 PST, David Kilzer (:ddkilzer)
no flags
Radar WebKit Bug Importer
Comment 1 2018-12-14 12:51:38 PST
David Kilzer (:ddkilzer)
Comment 2 2018-12-14 12:58:07 PST
Created attachment 357332 [details] Patch v1
Eric Carlson
Comment 3 2018-12-14 13:25:17 PST
Comment on attachment 357332 [details] Patch v1 Nice fix, thank you!
WebKit Commit Bot
Comment 4 2018-12-14 13:50:57 PST
Comment on attachment 357332 [details] Patch v1 Clearing flags on attachment: 357332 Committed r239232: <https://trac.webkit.org/changeset/239232>
WebKit Commit Bot
Comment 5 2018-12-14 13:50:58 PST
All reviewed patches have been landed. Closing bug.
Don Olmstead
Comment 6 2018-12-14 14:23:34 PST
Do we have any ideas on what clang-tidy rules should be run? I'd like to run it more often over the code base to see what it finds. Fujii is working on getting clang-cl working on Windows at which point we should be able to run it more. https://bugs.webkit.org/show_bug.cgi?id=171632 is a tracking bug for more general support for it in WebKit.
Darin Adler
Comment 7 2018-12-14 17:33:59 PST
Comment on attachment 357332 [details] Patch v1 View in context: https://bugs.webkit.org/attachment.cgi?id=357332&action=review > Source/WTF/wtf/Logger.h:47 > + template<typename U = T> static typename std::enable_if<std::is_same<typename std::remove_reference<U>::type, AtomicString>::value, String>::type toString(const AtomicString& argument) { return argument.string(); } This "copy" here is just a ref/deref pair. It was OK to make the change, but not critical.
David Kilzer (:ddkilzer)
Comment 8 2018-12-15 06:37:56 PST
(In reply to Darin Adler from comment #7) > Comment on attachment 357332 [details] > Patch v1 > > View in context: > https://bugs.webkit.org/attachment.cgi?id=357332&action=review > > > Source/WTF/wtf/Logger.h:47 > > + template<typename U = T> static typename std::enable_if<std::is_same<typename std::remove_reference<U>::type, AtomicString>::value, String>::type toString(const AtomicString& argument) { return argument.string(); } > > This "copy" here is just a ref/deref pair. It was OK to make the change, but > not critical. I know the object holding the actual string itself (AtomicStringImpl) is not copied, but why isn't the AtomicString container copied? AtomicString(const AtomicString& other) : m_string(other.m_string) { }
Darin Adler
Comment 9 2018-12-15 16:07:28 PST
The AtomicString is a class derived from String that adds no data members and String is just a structure with a RefPtr<StringImpl> in it. So what we are copying is a RefPtr. Just a ref/deref pair.
Note You need to log in before you can comment on or make changes to this bug.