[SERVER-68787] Coverity analysis defect 122591: AUTO_CAUSES_COPY Created: 12/Aug/22 Updated: 27/Oct/23 Resolved: 26/Aug/22 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Internal Code |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Coverity Collector User | Assignee: | Kevin Cherkauer |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | coverity, neweng | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Sprint: | QE 2022-09-05 |
| Participants: |
| Description |
|
AUTO_CAUSES_COPY Unnecessary object copies can affect performance. Using the auto keyword without an & causes a copy. |
| Comments |
| Comment by Kevin Cherkauer [ 26/Aug/22 ] |
|
The source of the range loop returns const iterators, so a copy is made to the loop variable as the loop changes the state of the copy, which it is not allowed to do to the original because of constness. |
| Comment by Githook User [ 26/Aug/22 ] |
|
Author: {'name': 'Kevin Cherkauer', 'email': 'kevin.cherkauer@mongodb.com', 'username': 'kevin-cherkauer'}Message: |
| Comment by Mickey Winters [ 12/Aug/22 ] |
|
I think we want a copy here since _sortPattern is a local variable. later in the serialize method we serialize with the original queries sort pattern. NOT the modified sort pattern we construct here. I could have expressed this better with const auto and explicitly making a copy |
| Comment by Kyle Suarez [ 12/Aug/22 ] |