Bug 148251 - Use std::swap instead of using temporary values
Summary: Use std::swap instead of using temporary values
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
(earliest affected)
Hardware: All All
: medium normal
Assignee: Not Assigned
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Blocks: Dev-related
  Show dependency treegraph
Reported: 2022-03-29 13:19 UTC by Paris Oplopoios
Modified: 2022-05-19 07:14 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:
Regression By:


Note You need to log in before you can comment on or make changes to this bug.
Description Paris Oplopoios 2022-03-29 13:19:42 UTC
There's places in code where a swap between two variables happens like this:

T temp = a;
a = b;
b = temp;

There's no need to clutter code with 3 lines where just one is enough:

std::swap(a, b);

Furthermore, std::swap uses move semantics which can improve performance for big data members.

How to find occurrences:

You can use this regex that currently finds 78 results:


[\n\r\s]+ matches newlines and spaces. This exhaustively searches for any weird combination of spaces between the type/variable names/semicolons

See this https://gerrit.libreoffice.org/c/core/+/132194 for an example

Steps to Reproduce:

Actual Results:

Expected Results:

Reproducible: Always

User Profile Reset: No

Additional Info:
Comment 1 Roman Kuznetsov 2022-03-29 13:39:00 UTC
Set to NEW