Back to index

lightning-sunbird  0.9+nobinonly
SizeTest02.cpp
Go to the documentation of this file.
00001 // Test02.cpp
00002 
00003 #include "nsIDOMNode.h"
00004 #include "nsCOMPtr.h"
00005 #include "nsString.h"
00006 
00007 #ifdef __MWERKS__
00008        #pragma exceptions off
00009 #endif
00010 
00011 NS_DEF_PTR(nsIDOMNode);
00012 
00013        /*
00014               This test file compares the generated code size of similar functions between raw
00015                 COM interface pointers (|AddRef|ing and |Release|ing by hand) and |nsCOMPtr|s.
00016 
00017               Function size results were determined by examining dissassembly of the generated code.
00018               mXXX is the size of the generated code on the Macintosh.  wXXX is the size on Windows.
00019               For these tests, all reasonable optimizations were enabled and exceptions were
00020               disabled (just as we build for release).
00021 
00022               The tests in this file explore more complicated functionality: assigning a pointer
00023                 to be reference counted into a [raw, nsCOMPtr] object using |QueryInterface|;
00024               ensuring that it is |AddRef|ed and |Release|d appropriately; calling through the pointer
00025               to a function supplied by the underlying COM interface.  The tests in this file expand
00026               on the tests in "Test01.cpp" by adding |QueryInterface|.
00027 
00028               Windows:
00029                      raw01                                                           52
00030                      nsCOMPtr                                                 63
00031                      raw                                                                    66
00032                      nsCOMPtr*                                                68
00033 
00034               Macintosh:
00035                      nsCOMPtr                                                120    (1.0000)
00036                      Raw01                                                          128           (1.1429)      i.e., 14.29% bigger than nsCOMPtr
00037                      Raw00                                                          144           (1.2000)
00038        */
00039 
00040 
00041 void // nsresult
00042 Test02_Raw00( nsISupports* aDOMNode, nsString* aResult )
00043               // m144, w66
00044        {
00045 // -- the following code is assumed, but is commented out so we compare only
00046 //             the relevent generated code
00047 
00048 //            if ( !aDOMNode )
00049 //                   return NS_ERROR_NULL_POINTER;
00050 
00051               nsIDOMNode* node = 0;
00052               nsresult status = aDOMNode->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node);
00053               if ( NS_SUCCEEDED(status) )
00054                      {
00055                             node->GetNodeName(*aResult);
00056                      }
00057 
00058               NS_IF_RELEASE(node);
00059 
00060 //            return status;
00061        }
00062 
00063 void // nsresult
00064 Test02_Raw01( nsISupports* aDOMNode, nsString* aResult )
00065               // m128, w52
00066        {
00067 //            if ( !aDOMNode )
00068 //                   return NS_ERROR_NULL_POINTER;
00069 
00070               nsIDOMNode* node;
00071                 nsresult status = aDOMNode->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node);
00072               if ( NS_SUCCEEDED(status) )
00073                      {
00074                             node->GetNodeName(*aResult);
00075                             NS_RELEASE(node);
00076                      }
00077 
00078 //            return status;
00079        }
00080 
00081 void // nsresult
00082 Test02_nsCOMPtr( nsISupports* aDOMNode, nsString* aResult )
00083               // m120, w63/68
00084        {
00085               nsresult status;
00086               nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aDOMNode, &status);
00087               
00088               if ( node )
00089                      node->GetNodeName(*aResult);
00090 
00091 //            return status;
00092        }
00093