Bug 1874684 - Part 4: Prefer const references instead of copying Instant values....
[gecko.git] / xpcom / tests / SizeTest02.cpp
blob2673bbe70df0558be227f199114b70f371f37173
1 // Test02.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 more complicated functionality: assigning
20 a pointer to be reference counted into a [raw, nsCOMPtr] object using
21 |QueryInterface|; ensuring that it is |AddRef|ed and |Release|d
22 appropriately; calling through the pointer to a function supplied by the
23 underlying COM interface. The tests in this file expand on the tests in
24 "Test01.cpp" by adding |QueryInterface|.
26 Windows:
27 raw01
28 52 nsCOMPtr 63 raw
29 66 nsCOMPtr* 68
31 Macintosh:
32 nsCOMPtr 120 (1.0000) Raw01
33 128 (1.1429) i.e., 14.29% bigger than nsCOMPtr Raw00
34 144 (1.2000)
37 void // nsresult
38 Test02_Raw00(nsISupports* aDOMNode, nsString* aResult)
39 // m144, w66
41 // -- the following code is assumed, but is commented out so we compare only
42 // the relevent generated code
44 // if ( !aDOMNode )
45 // return NS_ERROR_NULL_POINTER;
47 nsINode* node = 0;
48 nsresult status =
49 aDOMNode->QueryInterface(NS_GET_IID(nsINode), (void**)&node);
50 if (NS_SUCCEEDED(status)) {
51 node->GetNodeName(*aResult);
54 NS_IF_RELEASE(node);
56 // return status;
59 void // nsresult
60 Test02_Raw01(nsISupports* aDOMNode, nsString* aResult)
61 // m128, w52
63 // if ( !aDOMNode )
64 // return NS_ERROR_NULL_POINTER;
66 nsINode* node;
67 nsresult status =
68 aDOMNode->QueryInterface(NS_GET_IID(nsINode), (void**)&node);
69 if (NS_SUCCEEDED(status)) {
70 node->GetNodeName(*aResult);
71 NS_RELEASE(node);
74 // return status;
77 void // nsresult
78 Test02_nsCOMPtr(nsISupports* aDOMNode, nsString* aResult)
79 // m120, w63/68
81 nsresult status;
82 nsCOMPtr<nsINode> node = do_QueryInterface(aDOMNode, &status);
84 if (node) node->GetNodeName(*aResult);
86 // return status;