xpcom/tests/SizeTest02.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/tests/SizeTest02.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +// Test02.cpp
     1.5 +
     1.6 +#include "nsIDOMNode.h"
     1.7 +#include "nsCOMPtr.h"
     1.8 +#include "nsString.h"
     1.9 +
    1.10 +NS_DEF_PTR(nsIDOMNode);
    1.11 +
    1.12 +	/*
    1.13 +		This test file compares the generated code size of similar functions between raw
    1.14 +                COM interface pointers (|AddRef|ing and |Release|ing by hand) and |nsCOMPtr|s.
    1.15 +
    1.16 +		Function size results were determined by examining dissassembly of the generated code.
    1.17 +		mXXX is the size of the generated code on the Macintosh.  wXXX is the size on Windows.
    1.18 +		For these tests, all reasonable optimizations were enabled and exceptions were
    1.19 +		disabled (just as we build for release).
    1.20 +
    1.21 +		The tests in this file explore more complicated functionality: assigning a pointer
    1.22 +                to be reference counted into a [raw, nsCOMPtr] object using |QueryInterface|;
    1.23 +		ensuring that it is |AddRef|ed and |Release|d appropriately; calling through the pointer
    1.24 +		to a function supplied by the underlying COM interface.  The tests in this file expand
    1.25 +		on the tests in "Test01.cpp" by adding |QueryInterface|.
    1.26 +
    1.27 +		Windows:
    1.28 +			raw01									 52
    1.29 +			nsCOMPtr							 63
    1.30 +			raw										 66
    1.31 +			nsCOMPtr*							 68
    1.32 +
    1.33 +		Macintosh:
    1.34 +			nsCOMPtr							120 	(1.0000)
    1.35 +			Raw01									128		(1.1429)	i.e., 14.29% bigger than nsCOMPtr
    1.36 +			Raw00									144		(1.2000)
    1.37 +	*/
    1.38 +
    1.39 +
    1.40 +void // nsresult
    1.41 +Test02_Raw00( nsISupports* aDOMNode, nsString* aResult )
    1.42 +		// m144, w66
    1.43 +	{
    1.44 +// -- the following code is assumed, but is commented out so we compare only
    1.45 +//		 the relevent generated code
    1.46 +
    1.47 +//		if ( !aDOMNode )
    1.48 +//			return NS_ERROR_NULL_POINTER;
    1.49 +
    1.50 +		nsIDOMNode* node = 0;
    1.51 +		nsresult status = aDOMNode->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node);
    1.52 +		if ( NS_SUCCEEDED(status) )
    1.53 +			{
    1.54 +				node->GetNodeName(*aResult);
    1.55 +			}
    1.56 +
    1.57 +		NS_IF_RELEASE(node);
    1.58 +
    1.59 +//		return status;
    1.60 +	}
    1.61 +
    1.62 +void // nsresult
    1.63 +Test02_Raw01( nsISupports* aDOMNode, nsString* aResult )
    1.64 +		// m128, w52
    1.65 +	{
    1.66 +//		if ( !aDOMNode )
    1.67 +//			return NS_ERROR_NULL_POINTER;
    1.68 +
    1.69 +		nsIDOMNode* node;
    1.70 +                nsresult status = aDOMNode->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node);
    1.71 +		if ( NS_SUCCEEDED(status) )
    1.72 +			{
    1.73 +				node->GetNodeName(*aResult);
    1.74 +				NS_RELEASE(node);
    1.75 +			}
    1.76 +
    1.77 +//		return status;
    1.78 +	}
    1.79 +
    1.80 +void // nsresult
    1.81 +Test02_nsCOMPtr( nsISupports* aDOMNode, nsString* aResult )
    1.82 +		// m120, w63/68
    1.83 +	{
    1.84 +		nsresult status;
    1.85 +		nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aDOMNode, &status);
    1.86 +		
    1.87 +		if ( node )
    1.88 +			node->GetNodeName(*aResult);
    1.89 +
    1.90 +//		return status;
    1.91 +	}
    1.92 +

mercurial