Bug 392224 - Improve check "qstring-allocations". Replace QString::setNum with static version QString::number
Summary: Improve check "qstring-allocations". Replace QString::setNum with static vers...
Status: RESOLVED NOT A BUG
Alias: None
Product: clazy
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Unassigned bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-23 09:43 UTC by Roman
Modified: 2018-03-28 21:18 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roman 2018-03-23 09:43:10 UTC
Hi,

I just have found in my code string like this: 

QString str = QString().setNum(1234);

This can be replaced as:

QString str = QString::number(1234);

I checked Qt's source code and setNum() uses number() inside anyway. I assume calling setNum() like this should be case for "qstring-allocations".
Comment 1 Sergio Martins 2018-03-23 09:56:34 UTC
Only if the second form uses less memory allocations than the first. They might be the same, I'll have to check with heaptrack
Comment 2 Sergio Martins 2018-03-28 21:18:40 UTC
Tested with heaptrack, they are completely the same, regarding allocations, so not good for qstring-allocations.

Maybe could have some readability advantage though, but too thin for its own check, as each check adds overhead