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)
Tracking
()
RESOLVED
INVALID
People
(Reporter: dholbert, Unassigned)
References
Details
Attachments
(1 file)
1.33 KB,
patch
|
Details | Diff | Splinter Review |
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.
Reporter | ||
Comment 1•10 years ago
|
||
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.
Reporter | ||
Comment 2•10 years ago
|
||
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.
Description
•