Bug 1753166 [wpt PR 32658] - Return a result from the worker in MediaStreamTrack...
[gecko.git] / xpcom / tests / SizeTest01.cpp
blob790b0fa0325fc535796f931cac7fce4604a2315f
1 // Test01.cpp
3 #include "nsINode.h"
4 #include "nsCOMPtr.h"
5 #include "nsString.h"
7 NS_DEF_PTR(nsINode);
9 /*
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
12 |nsCOMPtr|s.
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.
24 Windows:
25 raw_optimized
26 31 bytes raw, nsCOMPtr*
27 34 nsCOMPtr_optimized*
28 38 nsCOMPtr_optimized
29 42 nsCOMPtr
32 Macintosh:
33 raw_optimized, nsCOMPtr_optimized
34 112 bytes (1.0000) nsCOMPtr
35 120 (1.0714) i.e., 7.14% bigger than
36 raw_optimized et al
37 raw
38 140 (1.2500)
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)
48 // m140, w34
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
54 |Test01_nsIPtr00|.
57 nsINode* node = aDOMNode;
58 NS_IF_ADDREF(node);
60 if (node) node->GetNodeName(*aResult);
62 NS_IF_RELEASE(node);
65 void Test01_raw_optimized(nsINode* aDOMNode, nsString* aResult)
66 // m112, w31
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
82 // if ( !aDOMNode )
83 // return;
85 nsINode* node = aDOMNode;
86 NS_ADDREF(node);
87 node->GetNodeName(*aResult);
88 NS_RELEASE(node);
91 void Test01_nsCOMPtr(nsINode* aDOMNode, nsString* aResult)
92 // m120, w46/34
94 nsCOMPtr<nsINode> node = aDOMNode;
96 if (node) node->GetNodeName(*aResult);
99 void Test01_nsCOMPtr_optimized(nsINode* aDOMNode, nsString* aResult)
100 // m112, w42/38
102 // if ( !aDOMNode )
103 // return;
105 nsCOMPtr<nsINode> node = aDOMNode;
106 node->GetNodeName(*aResult);