Closed
Bug 215421
Opened 21 years ago
Closed 20 years ago
AutoBuffer class template with class T and static_buffer_size as template parameters
Categories
(Core Graveyard :: GFX, defect)
Core Graveyard
GFX
Tracking
(Not tracked)
RESOLVED
DUPLICATE
of bug 233485
People
(Reporter: jshin1987, Assigned: kmcclusk)
References
Details
There are dozens of places in Gfx where the following pattern is used (some are hidden under the hood of macros): PRUnichar gBuffer[BUFFER_SIZE]; ....... In some function, PRUnichar *buffer= gBuffer; if ( len > BUFFER_SIZE) { buffer = new PRUnichar[len]; if (!buffer) return NS_ERROR_OUT_OF_MEMORY; } use buffer ..... if (buffer != gBuffer) delete [] buffer; It's not PRUnichar but other types(PRUint8, PRUint32) are used in this pattern as well. It'd be nice if we could write a portable AutoBuffer with two template parameters (class T, PRInt32 static_buffer_size). I used a simple implementation at http://lxr.mozilla.org/seamonkey/source/gfx/src/windows/nsFontMetricsWin.cpp#551 In nsFontMetricsXft.cpp, I just used a non-template version lest I'd introduce a portability problem with some picky Unix compilers. http://lxr.mozilla.org/seamonkey/source/gfx/src/gtk/nsFontMetricsXft.cpp#327 I'm filing this under gfx not because it's the best but because I'm not sure where to file this bug under. Please, feel free to change the component as you see fit. I think it needs to go somewhere under xpcom/ds because I also found that this may be useful in intl/ctl as well (bug 215219)
Reporter | ||
Comment 2•21 years ago
|
||
Thanks for the info. on bug 70870. This is a subset of bug 70870 in a sense. If bug 70870 is not gonna be fixed soon, would it be a good idea to implement this one first (with narrower scope than bug 70870) and later to recast it in terms of nsBuffer?
Since you are aiming at xpcom/ds, you might as well go for bug 70870 since scc said that the underlying infrastructure is there, meaning that the thorny portability issues have been worked out. However, extras (such as those Append/Insert/etc) can't be left out. Seems it is the desire to have those extras that has caused that there is nothing at all. It is not necessary to achieve "completeness" at the first shot.
Reporter | ||
Comment 4•21 years ago
|
||
> extras (such as those Append/Insert/etc) can't be left out.
You meant 'can be left out', didn't you? I don't know when I'll be able to
give it a shot. Anyway, I'll take a look at nsBuffer.
Yeah, that was a typo... I hadn't look at the foundational files that scc mentioned, but a quick look now seems to suggest those unadvertised (under-utilized) nsBufferHandle<PRUnichar>, nsAutoBufferHandle<PRUnichar> might do the job and be of help in your bug 215219.
Reporter | ||
Comment 6•21 years ago
|
||
Just a note to myself: nsTextFrame.cpp has nsAutoIndexBuffer http://lxr.mozilla.org/mozilla/source/layout/html/base/src/nsTextFrame.cpp#161 nsAutoTextBuffer is defined with several useful methods: http://lxr.mozilla.org/mozilla/source/layout/html/base/src/nsTextTransformer.h#100
Reporter | ||
Comment 7•20 years ago
|
||
resolving as dupe of bug 233485 which was fixed a while ago. *** This bug has been marked as a duplicate of 233485 ***
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → DUPLICATE
Updated•16 years ago
|
Product: Core → Core Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•