|
1 // Test02.cpp |
|
2 |
|
3 #include "nsIDOMNode.h" |
|
4 #include "nsCOMPtr.h" |
|
5 #include "nsString.h" |
|
6 |
|
7 NS_DEF_PTR(nsIDOMNode); |
|
8 |
|
9 /* |
|
10 This test file compares the generated code size of similar functions between raw |
|
11 COM interface pointers (|AddRef|ing and |Release|ing by hand) and |nsCOMPtr|s. |
|
12 |
|
13 Function size results were determined by examining dissassembly of the generated code. |
|
14 mXXX is the size of the generated code on the Macintosh. wXXX is the size on Windows. |
|
15 For these tests, all reasonable optimizations were enabled and exceptions were |
|
16 disabled (just as we build for release). |
|
17 |
|
18 The tests in this file explore more complicated functionality: assigning a pointer |
|
19 to be reference counted into a [raw, nsCOMPtr] object using |QueryInterface|; |
|
20 ensuring that it is |AddRef|ed and |Release|d appropriately; calling through the pointer |
|
21 to a function supplied by the underlying COM interface. The tests in this file expand |
|
22 on the tests in "Test01.cpp" by adding |QueryInterface|. |
|
23 |
|
24 Windows: |
|
25 raw01 52 |
|
26 nsCOMPtr 63 |
|
27 raw 66 |
|
28 nsCOMPtr* 68 |
|
29 |
|
30 Macintosh: |
|
31 nsCOMPtr 120 (1.0000) |
|
32 Raw01 128 (1.1429) i.e., 14.29% bigger than nsCOMPtr |
|
33 Raw00 144 (1.2000) |
|
34 */ |
|
35 |
|
36 |
|
37 void // nsresult |
|
38 Test02_Raw00( nsISupports* aDOMNode, nsString* aResult ) |
|
39 // m144, w66 |
|
40 { |
|
41 // -- the following code is assumed, but is commented out so we compare only |
|
42 // the relevent generated code |
|
43 |
|
44 // if ( !aDOMNode ) |
|
45 // return NS_ERROR_NULL_POINTER; |
|
46 |
|
47 nsIDOMNode* node = 0; |
|
48 nsresult status = aDOMNode->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node); |
|
49 if ( NS_SUCCEEDED(status) ) |
|
50 { |
|
51 node->GetNodeName(*aResult); |
|
52 } |
|
53 |
|
54 NS_IF_RELEASE(node); |
|
55 |
|
56 // return status; |
|
57 } |
|
58 |
|
59 void // nsresult |
|
60 Test02_Raw01( nsISupports* aDOMNode, nsString* aResult ) |
|
61 // m128, w52 |
|
62 { |
|
63 // if ( !aDOMNode ) |
|
64 // return NS_ERROR_NULL_POINTER; |
|
65 |
|
66 nsIDOMNode* node; |
|
67 nsresult status = aDOMNode->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node); |
|
68 if ( NS_SUCCEEDED(status) ) |
|
69 { |
|
70 node->GetNodeName(*aResult); |
|
71 NS_RELEASE(node); |
|
72 } |
|
73 |
|
74 // return status; |
|
75 } |
|
76 |
|
77 void // nsresult |
|
78 Test02_nsCOMPtr( nsISupports* aDOMNode, nsString* aResult ) |
|
79 // m120, w63/68 |
|
80 { |
|
81 nsresult status; |
|
82 nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aDOMNode, &status); |
|
83 |
|
84 if ( node ) |
|
85 node->GetNodeName(*aResult); |
|
86 |
|
87 // return status; |
|
88 } |
|
89 |