Optimize IndexedString::byteArray
AbandonedPublic

Authored by kfunk on Sep 6 2015, 4:50 PM.

Details

Reviewers
mwolff
Group Reviewers
KDevelop
Summary

There's no need to perform a deep copy of the underlying c string.
Checked uses on LXR, this method is used in accordance with the new
semantics already.

Diff Detail

Repository
R33 KDevPlatform
Branch
master
Lint
Lint Skipped
Unit
Unit Tests Skipped
kfunk updated this revision to Diff 764.Sep 6 2015, 4:50 PM
kfunk retitled this revision from to Optimize IndexedString::byteArray.
kfunk updated this object.
kfunk edited the test plan for this revision. (Show Details)
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptSep 6 2015, 4:50 PM
kfunk added a project: KDevelop.
mwolff added a subscriber: mwolff.Sep 6 2015, 5:56 PM

This is very unsafe. When you put QByteArray anywhere and then destroy the IndexedString it may (eventually) trigger a cleanup of the item repo data, which will make the QByteArray reference destroyed data.

Where is this actually required? If possible, I want to delete the bytearray getter completely, as it can lead to unicode issues.

kfunk added a comment.EditedSep 6 2015, 6:51 PM
In D327#6248, @mwolff wrote:

This is very unsafe. When you put QByteArray anywhere and then destroy the IndexedString it may (eventually) trigger a cleanup of the item repo data, which will make the QByteArray reference destroyed data.

Right, but "you have been warned" in the documentation.

Where is this actually required? If possible, I want to delete the bytearray getter completely, as it can lead to unicode issues.

Only used in kdevplatform/kdevelop afaics. Just removing seems possible; a few locations (around 10) in oldcpp need fixing (trivial). Will do.

Unfortunately code such as:

ret += KDevelop::IndexedString::fromIndex(contents[a]).byteArray();

would turn a bit unreadable.

Maybe renaming to asByteArray would give sufficient hint the returned value is just a reference, not a copy for now. Otherwise I'd just ditch the patch for now.

mwolff requested changes to this revision.Oct 8 2015, 10:13 AM
mwolff added a reviewer: mwolff.

I don't like it as-is, as I said. actually, the other unsafe API is could also be removed in the future (i.e. the fromIndex stuff).

This revision now requires changes to proceed.Oct 8 2015, 10:13 AM
kfunk abandoned this revision.Nov 2 2015, 9:38 PM