Commit 90b68cb
committed
QMap: don't detach in take()
When shared, the old use used detach(), thereby copying the key (and
must needs allocating a node for it) just to extract it again in the
next step. While this is easy to understand, it has several problems:
First, we allocate a node for the to-be-removed item just to remove it
again (deallocating the node again). This is inefficient.
Second, because on detach(), we drop our own reference to the old data
early on in the function, a separate thread can drop its reference and
delete the old data while we still execute and reference 'key', which
may be an alias to a key in the old data. This was known and we
protected against it by taking _an extra copy_ of *this to retain the
reference to the old data for the remainder of the function. This is
also inefficient, because, while we anyway deep-copy, the ref-count
manipulations, being atomic, may actually dominate the runtime for
small maps.
So, as described in general in the detach-remove epic (QTBUG-103329),
build a new container, and swap() it into place. This solves both
problems while minimizing overhead.
Not picking to 6.8 and earlier, as we don't need to (optimization) and
the diff is very localized, so shouldn't affect cherry-picking of fixes
in adjacent lines.
Task-number: QTBUG-106170
Pick-to: 6.11 6.10
Change-Id: Ia9a9e72c85398e85c963c309b42d94482a4b6759
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>1 parent 49a6626 commit 90b68cb
1 file changed
+40
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
328 | 329 | | |
329 | 330 | | |
330 | 331 | | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
335 | 371 | | |
336 | 372 | | |
337 | 373 | | |
| |||
0 commit comments