SizeTest02.cpp 2.3 KB

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