Bug 192710 - clang-tidy: Fix unnecessary copy of AtomicString each time one is logged
Summary: clang-tidy: Fix unnecessary copy of AtomicString each time one is logged
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: David Kilzer (:ddkilzer)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-12-14 12:51 PST by David Kilzer (:ddkilzer)
Modified: 2018-12-15 16:07 PST (History)
11 users (show)

See Also:


Attachments
Patch v1 (2.47 KB, patch)
2018-12-14 12:58 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 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       &
Comment 1 Radar WebKit Bug Importer 2018-12-14 12:51:38 PST
<rdar://problem/46738962>
Comment 2 David Kilzer (:ddkilzer) 2018-12-14 12:58:07 PST
Created attachment 357332 [details]
Patch v1
Comment 3 Eric Carlson 2018-12-14 13:25:17 PST
Comment on attachment 357332 [details]
Patch v1

Nice fix, thank you!
Comment 4 WebKit Commit Bot 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>
Comment 5 WebKit Commit Bot 2018-12-14 13:50:58 PST
All reviewed patches have been landed.  Closing bug.
Comment 6 Don Olmstead 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.
Comment 7 Darin Adler 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.
Comment 8 David Kilzer (:ddkilzer) 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) { }
Comment 9 Darin Adler 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.