Improve + = operator performance

I am writing an application that should be very fast. I am using Qt 5.5 with Qt Creator, the 64-bit MSVC2013 compiled version of Qt.

I used very sleepy CS to profile my application, and I saw that the function that took the most exclusive time was the + = overload operator (which is called, as you assume, many times).

Here is a snippet of code.

struct Coordinate
{
    float                   x;
    float                   y;

    Coordinate operator+=(const Coordinate &coord)
    {
        this->x += coord.x;
        this->y += coord.y;
        return (*this);
    }
};

I wondered if there is a way to improve the performance of such a simple function like this.

+4
source share
2 answers

operator+=not quite defined the way you did it. Rather, it should be :

Coordinate& operator+=(const Coordinate &coord);

Note the return value of the link.

.

+18

, . Release . inlined .

+3

Source: https://habr.com/ru/post/1625488/


All Articles