Bug 392224

Summary: Improve check "qstring-allocations". Replace QString::setNum with static version QString::number
Product: [Developer tools] clazy Reporter: Roman <dismine>
Component: generalAssignee: Unassigned bugs <unassigned-bugs-null>
Status: RESOLVED NOT A BUG    
Severity: wishlist CC: smartins
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

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