Open
Bug 565255
Opened 14 years ago
Updated 2 years ago
Add the ability for nsAString to CompressWhiteSpace()
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
NEW
People
(Reporter: MarcoZ, Unassigned)
References
(Blocks 2 open bugs)
Details
So that copies like this can be eliminated: http://mxr.mozilla.org/mozilla-central/source/accessible/src/base/nsAccessible.cpp#268
Updated•14 years ago
|
Comment 1•14 years ago
|
||
It's usually not a copy. Let's assume that the attribute is being stored in a string buffer, rather than as an integer or float or some such. The GetAttr call then returns a reference to the buffer. The CompressWhitespace call first creates a copy of the buffer, then trims and compresses it. The assignment then gives the out parameter a reference to the compressed copy of the buffer. So in fact the auto part of the string is wasted in this particular case. The behaviour is slightly different for a non-string attribute. In this case, the GetAttr call would probably copy the result into the auto buffer, CompressWhitespace would "compress" the auto buffer in-place, then the auto buffer would be copied into the caller. You might be able to micro-optimise this by using an nsString temporary, in which case the GetAttr call would create a string buffer, CompressWhitespace would "compress" it in-place, then the out parameter would get a reference to this buffer. But this depends on the out parameter actually preferring to get a string buffer, since the creation of the buffer would involve an expensive memory allocation.
Comment 2•14 years ago
|
||
I don't think we deal a lot with non-string attributes when we compute the accessible name. I'm happy to know GetAttr is optimal for string attributes. Therefore perhaps we don't need to do anything in this bug. However syntax is a bit confusing because nsAutoString str; aStr = str; makes me think the string is copied and probably it's worth to be fixed.
Comment 3•14 years ago
|
||
A string can be in one of the following states: 1. Void. The string is not copied, instead the destination is voided. 2. Empty. The string is not copied, instead the destination is truncated. 3. Shared. The string is not copied, instead the buffer is shared. 4. Owned. 5. Fixed. 6. Dependent. The string is copied. The copy is fixed if the destination supports it (auto string), otherwise it is shared.
Comment 4•14 years ago
|
||
I need to read accessible name computation code carefully but it sounds we compress whitespaces on strings obtained from GetAttr what should return shared buffer if I get right. I concerned to syntax we use, I meant it's not evident that aStr = str doesn't copy in our case and it might be considered as a worth to fix. If CompressWhitespace will be allowed on nsAString then we pass aStr argument into GetAttr and call CompressWhitespace on it. That should look nicer than having what we have now. Does it make sense?
Assignee | ||
Updated•3 years ago
|
Component: String → XPCOM
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•