michael@0: // Test02.cpp michael@0: michael@0: #include "nsIDOMNode.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsString.h" michael@0: michael@0: NS_DEF_PTR(nsIDOMNode); michael@0: michael@0: /* michael@0: This test file compares the generated code size of similar functions between raw michael@0: COM interface pointers (|AddRef|ing and |Release|ing by hand) and |nsCOMPtr|s. michael@0: michael@0: Function size results were determined by examining dissassembly of the generated code. michael@0: mXXX is the size of the generated code on the Macintosh. wXXX is the size on Windows. michael@0: For these tests, all reasonable optimizations were enabled and exceptions were michael@0: disabled (just as we build for release). michael@0: michael@0: The tests in this file explore more complicated functionality: assigning a pointer michael@0: to be reference counted into a [raw, nsCOMPtr] object using |QueryInterface|; michael@0: ensuring that it is |AddRef|ed and |Release|d appropriately; calling through the pointer michael@0: to a function supplied by the underlying COM interface. The tests in this file expand michael@0: on the tests in "Test01.cpp" by adding |QueryInterface|. michael@0: michael@0: Windows: michael@0: raw01 52 michael@0: nsCOMPtr 63 michael@0: raw 66 michael@0: nsCOMPtr* 68 michael@0: michael@0: Macintosh: michael@0: nsCOMPtr 120 (1.0000) michael@0: Raw01 128 (1.1429) i.e., 14.29% bigger than nsCOMPtr michael@0: Raw00 144 (1.2000) michael@0: */ michael@0: michael@0: michael@0: void // nsresult michael@0: Test02_Raw00( nsISupports* aDOMNode, nsString* aResult ) michael@0: // m144, w66 michael@0: { michael@0: // -- the following code is assumed, but is commented out so we compare only michael@0: // the relevent generated code michael@0: michael@0: // if ( !aDOMNode ) michael@0: // return NS_ERROR_NULL_POINTER; michael@0: michael@0: nsIDOMNode* node = 0; michael@0: nsresult status = aDOMNode->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node); michael@0: if ( NS_SUCCEEDED(status) ) michael@0: { michael@0: node->GetNodeName(*aResult); michael@0: } michael@0: michael@0: NS_IF_RELEASE(node); michael@0: michael@0: // return status; michael@0: } michael@0: michael@0: void // nsresult michael@0: Test02_Raw01( nsISupports* aDOMNode, nsString* aResult ) michael@0: // m128, w52 michael@0: { michael@0: // if ( !aDOMNode ) michael@0: // return NS_ERROR_NULL_POINTER; michael@0: michael@0: nsIDOMNode* node; michael@0: nsresult status = aDOMNode->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node); michael@0: if ( NS_SUCCEEDED(status) ) michael@0: { michael@0: node->GetNodeName(*aResult); michael@0: NS_RELEASE(node); michael@0: } michael@0: michael@0: // return status; michael@0: } michael@0: michael@0: void // nsresult michael@0: Test02_nsCOMPtr( nsISupports* aDOMNode, nsString* aResult ) michael@0: // m120, w63/68 michael@0: { michael@0: nsresult status; michael@0: nsCOMPtr node = do_QueryInterface(aDOMNode, &status); michael@0: michael@0: if ( node ) michael@0: node->GetNodeName(*aResult); michael@0: michael@0: // return status; michael@0: } michael@0: