Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | // Test01.cpp |
michael@0 | 2 | |
michael@0 | 3 | #include "nsIDOMNode.h" |
michael@0 | 4 | #include "nsCOMPtr.h" |
michael@0 | 5 | #include "nsString.h" |
michael@0 | 6 | |
michael@0 | 7 | NS_DEF_PTR(nsIDOMNode); |
michael@0 | 8 | |
michael@0 | 9 | /* |
michael@0 | 10 | This test file compares the generated code size of similar functions between raw |
michael@0 | 11 | COM interface pointers (|AddRef|ing and |Release|ing by hand) and |nsCOMPtr|s. |
michael@0 | 12 | |
michael@0 | 13 | Function size results were determined by examining dissassembly of the generated code. |
michael@0 | 14 | mXXX is the size of the generated code on the Macintosh. wXXX is the size on Windows. |
michael@0 | 15 | For these tests, all reasonable optimizations were enabled and exceptions were |
michael@0 | 16 | disabled (just as we build for release). |
michael@0 | 17 | |
michael@0 | 18 | The tests in this file explore only the simplest functionality: assigning a pointer |
michael@0 | 19 | to be reference counted into a [raw, nsCOMPtr] object; ensuring that it is |
michael@0 | 20 | |AddRef|ed and |Release|d appropriately; calling through the pointer to a function |
michael@0 | 21 | supplied by the underlying COM interface. |
michael@0 | 22 | |
michael@0 | 23 | Windows: |
michael@0 | 24 | raw_optimized 31 bytes |
michael@0 | 25 | raw, nsCOMPtr* 34 |
michael@0 | 26 | nsCOMPtr_optimized* 38 |
michael@0 | 27 | nsCOMPtr_optimized 42 |
michael@0 | 28 | nsCOMPtr 46 |
michael@0 | 29 | |
michael@0 | 30 | Macintosh: |
michael@0 | 31 | raw_optimized, nsCOMPtr_optimized 112 bytes (1.0000) |
michael@0 | 32 | nsCOMPtr 120 (1.0714) i.e., 7.14% bigger than raw_optimized et al |
michael@0 | 33 | raw 140 (1.2500) |
michael@0 | 34 | |
michael@0 | 35 | The overall difference in size between Windows and Macintosh is caused by the |
michael@0 | 36 | the PowerPC RISC architecture where every instruction is 4 bytes. |
michael@0 | 37 | |
michael@0 | 38 | On Macintosh, nsCOMPtr generates out-of-line destructors which are |
michael@0 | 39 | not referenced, and which can be stripped by the linker. |
michael@0 | 40 | */ |
michael@0 | 41 | |
michael@0 | 42 | void |
michael@0 | 43 | Test01_raw( nsIDOMNode* aDOMNode, nsString* aResult ) |
michael@0 | 44 | // m140, w34 |
michael@0 | 45 | { |
michael@0 | 46 | /* |
michael@0 | 47 | This test is designed to be more like a typical large function where, |
michael@0 | 48 | because you are working with several resources, you don't just return when |
michael@0 | 49 | one of them is |nullptr|. Similarly: |Test01_nsCOMPtr00|, and |Test01_nsIPtr00|. |
michael@0 | 50 | */ |
michael@0 | 51 | |
michael@0 | 52 | nsIDOMNode* node = aDOMNode; |
michael@0 | 53 | NS_IF_ADDREF(node); |
michael@0 | 54 | |
michael@0 | 55 | if ( node ) |
michael@0 | 56 | node->GetNodeName(*aResult); |
michael@0 | 57 | |
michael@0 | 58 | NS_IF_RELEASE(node); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | void |
michael@0 | 62 | Test01_raw_optimized( nsIDOMNode* aDOMNode, nsString* aResult ) |
michael@0 | 63 | // m112, w31 |
michael@0 | 64 | { |
michael@0 | 65 | /* |
michael@0 | 66 | This test simulates smaller functions where you _do_ just return |
michael@0 | 67 | |nullptr| at the first sign of trouble. Similarly: |Test01_nsCOMPtr01|, |
michael@0 | 68 | and |Test01_nsIPtr01|. |
michael@0 | 69 | */ |
michael@0 | 70 | |
michael@0 | 71 | /* |
michael@0 | 72 | This test produces smaller code that |Test01_raw| because it avoids |
michael@0 | 73 | the three tests: |NS_IF_...|, and |if ( node )|. |
michael@0 | 74 | */ |
michael@0 | 75 | |
michael@0 | 76 | // -- the following code is assumed, but is commented out so we compare only |
michael@0 | 77 | // the relevent generated code |
michael@0 | 78 | |
michael@0 | 79 | // if ( !aDOMNode ) |
michael@0 | 80 | // return; |
michael@0 | 81 | |
michael@0 | 82 | nsIDOMNode* node = aDOMNode; |
michael@0 | 83 | NS_ADDREF(node); |
michael@0 | 84 | node->GetNodeName(*aResult); |
michael@0 | 85 | NS_RELEASE(node); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | void |
michael@0 | 89 | Test01_nsCOMPtr( nsIDOMNode* aDOMNode, nsString* aResult ) |
michael@0 | 90 | // m120, w46/34 |
michael@0 | 91 | { |
michael@0 | 92 | nsCOMPtr<nsIDOMNode> node = aDOMNode; |
michael@0 | 93 | |
michael@0 | 94 | if ( node ) |
michael@0 | 95 | node->GetNodeName(*aResult); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | void |
michael@0 | 99 | Test01_nsCOMPtr_optimized( nsIDOMNode* aDOMNode, nsString* aResult ) |
michael@0 | 100 | // m112, w42/38 |
michael@0 | 101 | { |
michael@0 | 102 | // if ( !aDOMNode ) |
michael@0 | 103 | // return; |
michael@0 | 104 | |
michael@0 | 105 | nsCOMPtr<nsIDOMNode> node = aDOMNode; |
michael@0 | 106 | node->GetNodeName(*aResult); |
michael@0 | 107 | } |