10 This test file compares the generated code size of similar functions
11 between raw COM interface pointers (|AddRef|ing and |Release|ing by hand) and
14 Function size results were determined by examining dissassembly of the
15 generated code. mXXX is the size of the generated code on the Macintosh. wXXX
16 is the size on Windows. For these tests, all reasonable optimizations were
17 enabled and exceptions were disabled (just as we build for release).
19 The tests in this file explore only the simplest functionality:
20 assigning a pointer to be reference counted into a [raw, nsCOMPtr] object;
21 ensuring that it is |AddRef|ed and |Release|d appropriately; calling through
22 the pointer to a function supplied by the underlying COM interface.
26 31 bytes raw, nsCOMPtr*
27 34 nsCOMPtr_optimized*
33 raw_optimized, nsCOMPtr_optimized
34 112 bytes (1.0000) nsCOMPtr
35 120 (1.0714) i.e., 7.14% bigger than
40 The overall difference in size between Windows and Macintosh is caused
41 by the the PowerPC RISC architecture where every instruction is 4 bytes.
43 On Macintosh, nsCOMPtr generates out-of-line destructors which are
44 not referenced, and which can be stripped by the linker.
47 void Test01_raw(nsINode
* aDOMNode
, nsString
* aResult
)
51 This test is designed to be more like a typical large function where,
52 because you are working with several resources, you don't just return
53 when one of them is |nullptr|. Similarly: |Test01_nsCOMPtr00|, and
57 nsINode
* node
= aDOMNode
;
60 if (node
) node
->GetNodeName(*aResult
);
65 void Test01_raw_optimized(nsINode
* aDOMNode
, nsString
* aResult
)
69 This test simulates smaller functions where you _do_ just return
70 |nullptr| at the first sign of trouble. Similarly:
71 |Test01_nsCOMPtr01|, and |Test01_nsIPtr01|.
75 This test produces smaller code that |Test01_raw| because it avoids
76 the three tests: |NS_IF_...|, and |if ( node )|.
79 // -- the following code is assumed, but is commented out so we compare only
80 // the relevent generated code
85 nsINode
* node
= aDOMNode
;
87 node
->GetNodeName(*aResult
);
91 void Test01_nsCOMPtr(nsINode
* aDOMNode
, nsString
* aResult
)
94 nsCOMPtr
<nsINode
> node
= aDOMNode
;
96 if (node
) node
->GetNodeName(*aResult
);
99 void Test01_nsCOMPtr_optimized(nsINode
* aDOMNode
, nsString
* aResult
)
105 nsCOMPtr
<nsINode
> node
= aDOMNode
;
106 node
->GetNodeName(*aResult
);