D15426: Avoid QByteArray::remove in AccessManagerReply::readData

Fabian Vogt noreply at phabricator.kde.org
Wed Sep 12 14:42:35 BST 2018


fvogt added a comment.


  In D15426#324636 <https://phabricator.kde.org/D15426#324636>, @bruns wrote:
  
  > In D15426#324486 <https://phabricator.kde.org/D15426#324486>, @fvogt wrote:
  >
  > > In D15426#324284 <https://phabricator.kde.org/D15426#324284>, @bruns wrote:
  > >
  > > > For the trivial case, do the clear in `readData()`.
  > > >
  > > > For the non-trivial case:
  > > >
  > > > 1. in `readData()`, no memmoves were ever done. Currently, if you have e.g. 50 kB in m_data, you read 2 * 16 kB, and move the remaining 18 kB to the front. You can instead just read 3 * 16 + 2 kB.
  > >
  > >
  > > It's always a cpu/memory trade off. I prefer KISS to premature optimization.
  >
  >
  > if you remove the `|| m_offset * 2 >= m_data.length()`, it gets even simpler, and does less work (especially for the readAll() case). The garbage collection is already done in slotData.
  
  
  I did not remove that because it means even if there's only a single byte in the buffer remaining (for some reason), the memory of `m_data` is never freed.
  
  However, I looked at the QByteArray source code and found that `:remove` doesn't actually change the capacity of the array at all, so it's indeed a bit pointless.

REPOSITORY
  R241 KIO

REVISION DETAIL
  https://phabricator.kde.org/D15426

To: fvogt, #frameworks, elvisangelaccio
Cc: ngraham, bruns, kde-frameworks-devel, michaelh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20180912/fe286995/attachment.html>


More information about the Kde-frameworks-devel mailing list