Closed Bug 1145258 Opened 10 years ago Closed 10 years ago

Create a version of LogicalSize::.ConvertTo that returns a const reference, to reduce copying

Categories

(Core :: Layout, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: dholbert, Unassigned)

References

Details

Attachments

(1 file)

Right now, LogicalSize::ConvertTo always requires a copy. (It returns type "LogicalSize".) It seems like we should optimize for the common case where the "from" & "to" writing-mode are the same, and no copy is needed. (In that case, we can just return a const reference to "this"). I think we can do this & still return a temporary LogicalSize if we change the return type to "const LogicalSize&". Then, in the uncommon case where the "to" writing-mode is different, the C++ rule about const-reference-prolonging-the-life-of-a-temporary will kick in & make it OK to return a reference to a local variable.
Depends on: 735577
Actually, this might be impossible... I tried to write a trivial fix for this, but I think I was misremembering how const-reference-to-temporary lifetime-extension works. (I recall that it's weird & slightly-counterintuitive, but it apparently doesn't work how I thought I remembered it working.) I thought this might do it, but clang gives me this warning (treated as an error in this directory)... > WritingModes.h:706:12: error: returning reference to local temporary object [-Werror,-Wreturn-stack-address] ...for the "return LogicalPoint(...)" statement.
Resolving as INVALID, but if it turns out this is possible, feel free to reopen & post a working fix/strategy.
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: