return-by-reference for Object field access
Can somebody explain why we use return-by-reference to access object-fields?
Код:
const int32& GetInt32Value(uint16 index) const (Historical note: we do this since long forgotten times) |
A discussion of a different yet related matter:
https://github.com/mangos/server/com...omment-1673031 |
Code inlined and in result this is array access. For small size types i think no difference, it's just consistent with way how this used for large structures access for avoid copy constructor call.
|
I always pass POD types by value if they fit into 64-bit register.
As some people here said in theory compiler can optimize out access by reference but no one proved that average compiler can into such stuff. Same with 'const'. I heard it can lead to better optimization by compiler but no one have real examples. |
Maybe you right, i not have personal strong points against use return values instead refs for types fit to 64-bits.
|
Текущее время: 16:16. Часовой пояс GMT +3. |
ru-mangos.ru - Русское сообщество MaNGOS