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 | // |reftest| random -- bogus perf test (bug 467263) |
michael@0 | 2 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* |
michael@0 | 8 | * |
michael@0 | 9 | * Date: 14 Feb 2002 |
michael@0 | 10 | * SUMMARY: Performance: Regexp performance degraded from 4.7 |
michael@0 | 11 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=85721 |
michael@0 | 12 | * |
michael@0 | 13 | * Adjust this testcase if necessary. The FAST constant defines |
michael@0 | 14 | * an upper bound in milliseconds for any execution to take. |
michael@0 | 15 | * |
michael@0 | 16 | */ |
michael@0 | 17 | //----------------------------------------------------------------------------- |
michael@0 | 18 | var BUGNUMBER = 85721; |
michael@0 | 19 | var summary = 'Performance: execution of regular expression'; |
michael@0 | 20 | var FAST = 100; // execution should be 100 ms or less to pass the test |
michael@0 | 21 | var MSG_FAST = 'Execution took less than ' + FAST + ' ms'; |
michael@0 | 22 | var MSG_SLOW = 'Execution took '; |
michael@0 | 23 | var MSG_MS = ' ms'; |
michael@0 | 24 | var str = ''; |
michael@0 | 25 | var re = ''; |
michael@0 | 26 | var status = ''; |
michael@0 | 27 | var actual = ''; |
michael@0 | 28 | var expect= ''; |
michael@0 | 29 | |
michael@0 | 30 | printBugNumber(BUGNUMBER); |
michael@0 | 31 | printStatus (summary); |
michael@0 | 32 | |
michael@0 | 33 | |
michael@0 | 34 | function elapsedTime(startTime) |
michael@0 | 35 | { |
michael@0 | 36 | return new Date() - startTime; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | |
michael@0 | 40 | function isThisFast(ms) |
michael@0 | 41 | { |
michael@0 | 42 | if (ms <= FAST) |
michael@0 | 43 | return MSG_FAST; |
michael@0 | 44 | return MSG_SLOW + ms + MSG_MS; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | |
michael@0 | 48 | |
michael@0 | 49 | /* |
michael@0 | 50 | * The first regexp. We'll test for performance (Section 1) and accuracy (Section 2). |
michael@0 | 51 | */ |
michael@0 | 52 | str='<sql:connection id="conn1"> <sql:url>www.m.com</sql:url> <sql:driver>drive.class</sql:driver>\n<sql:userId>foo</sql:userId> <sql:password>goo</sql:password> </sql:connection>'; |
michael@0 | 53 | re = /<sql:connection id="([^\r\n]*?)">\s*<sql:url>\s*([^\r\n]*?)\s*<\/sql:url>\s*<sql:driver>\s*([^\r\n]*?)\s*<\/sql:driver>\s*(\s*<sql:userId>\s*([^\r\n]*?)\s*<\/sql:userId>\s*)?\s*(\s*<sql:password>\s*([^\r\n]*?)\s*<\/sql:password>\s*)?\s*<\/sql:connection>/; |
michael@0 | 54 | expect = Array("<sql:connection id=\"conn1\"> <sql:url>www.m.com</sql:url> <sql:driver>drive.class</sql:driver>\n<sql:userId>foo</sql:userId> <sql:password>goo</sql:password> </sql:connection>","conn1","www.m.com","drive.class","<sql:userId>foo</sql:userId> ","foo","<sql:password>goo</sql:password> ","goo"); |
michael@0 | 55 | |
michael@0 | 56 | /* |
michael@0 | 57 | * Check performance - |
michael@0 | 58 | */ |
michael@0 | 59 | status = inSection(1); |
michael@0 | 60 | var start = new Date(); |
michael@0 | 61 | var result = re.exec(str); |
michael@0 | 62 | actual = elapsedTime(start); |
michael@0 | 63 | reportCompare(isThisFast(FAST), isThisFast(actual), status); |
michael@0 | 64 | |
michael@0 | 65 | /* |
michael@0 | 66 | * Check accuracy - |
michael@0 | 67 | */ |
michael@0 | 68 | status = inSection(2); |
michael@0 | 69 | testRegExp([status], [re], [str], [result], [expect]); |
michael@0 | 70 | |
michael@0 | 71 | |
michael@0 | 72 | |
michael@0 | 73 | /* |
michael@0 | 74 | * The second regexp (HUGE!). We'll test for performance (Section 3) and accuracy (Section 4). |
michael@0 | 75 | * It comes from the O'Reilly book "Mastering Regular Expressions" by Jeffrey Friedl, Appendix B |
michael@0 | 76 | */ |
michael@0 | 77 | |
michael@0 | 78 | //# Some things for avoiding backslashitis later on. |
michael@0 | 79 | $esc = '\\\\'; |
michael@0 | 80 | $Period = '\.'; |
michael@0 | 81 | $space = '\040'; $tab = '\t'; |
michael@0 | 82 | $OpenBR = '\\['; $CloseBR = '\\]'; |
michael@0 | 83 | $OpenParen = '\\('; $CloseParen = '\\)'; |
michael@0 | 84 | $NonASCII = '\x80-\xff'; $ctrl = '\000-\037'; |
michael@0 | 85 | $CRlist = '\n\015'; //# note: this should really be only \015. |
michael@0 | 86 | // Items 19, 20, 21 |
michael@0 | 87 | $qtext = '[^' + $esc + $NonASCII + $CRlist + '\"]'; // # for within "..." |
michael@0 | 88 | $dtext = '[^' + $esc + $NonASCII + $CRlist + $OpenBR + $CloseBR + ']'; // # for within [...] |
michael@0 | 89 | $quoted_pair = $esc + '[^' + $NonASCII + ']'; // # an escaped character |
michael@0 | 90 | |
michael@0 | 91 | //############################################################################## |
michael@0 | 92 | //# Items 22 and 23, comment. |
michael@0 | 93 | //# Impossible to do properly with a regex, I make do by allowing at most one level of nesting. |
michael@0 | 94 | $ctext = '[^' + $esc + $NonASCII + $CRlist + '()]'; |
michael@0 | 95 | |
michael@0 | 96 | //# $Cnested matches one non-nested comment. |
michael@0 | 97 | //# It is unrolled, with normal of $ctext, special of $quoted_pair. |
michael@0 | 98 | $Cnested = |
michael@0 | 99 | $OpenParen + // # ( |
michael@0 | 100 | $ctext + '*' + // # normal* |
michael@0 | 101 | '(?:' + $quoted_pair + $ctext + '*)*' + // # (special normal*)* |
michael@0 | 102 | $CloseParen; // # ) |
michael@0 | 103 | |
michael@0 | 104 | |
michael@0 | 105 | //# $comment allows one level of nested parentheses |
michael@0 | 106 | //# It is unrolled, with normal of $ctext, special of ($quoted_pair|$Cnested) |
michael@0 | 107 | $comment = |
michael@0 | 108 | $OpenParen + // # ( |
michael@0 | 109 | $ctext + '*' + // # normal* |
michael@0 | 110 | '(?:' + // # ( |
michael@0 | 111 | '(?:' + $quoted_pair + '|' + $Cnested + ')' + // # special |
michael@0 | 112 | $ctext + '*' + // # normal* |
michael@0 | 113 | ')*' + // # )* |
michael@0 | 114 | $CloseParen; // # ) |
michael@0 | 115 | |
michael@0 | 116 | |
michael@0 | 117 | //############################################################################## |
michael@0 | 118 | //# $X is optional whitespace/comments. |
michael@0 | 119 | $X = |
michael@0 | 120 | '[' + $space + $tab + ']*' + // # Nab whitespace. |
michael@0 | 121 | '(?:' + $comment + '[' + $space + $tab + ']*)*'; // # If comment found, allow more spaces. |
michael@0 | 122 | |
michael@0 | 123 | |
michael@0 | 124 | //# Item 10: atom |
michael@0 | 125 | $atom_char = '[^(' + $space + '<>\@,;:\".' + $esc + $OpenBR + $CloseBR + $ctrl + $NonASCII + ']'; |
michael@0 | 126 | $atom = |
michael@0 | 127 | $atom_char + '+' + // # some number of atom characters... |
michael@0 | 128 | '(?!' + $atom_char + ')'; // # ..not followed by something that could be part of an atom |
michael@0 | 129 | |
michael@0 | 130 | // # Item 11: doublequoted string, unrolled. |
michael@0 | 131 | $quoted_str = |
michael@0 | 132 | '\"' + // # " |
michael@0 | 133 | $qtext + '*' + // # normal |
michael@0 | 134 | '(?:' + $quoted_pair + $qtext + '*)*' + // # ( special normal* )* |
michael@0 | 135 | '\"'; // # " |
michael@0 | 136 | |
michael@0 | 137 | //# Item 7: word is an atom or quoted string |
michael@0 | 138 | $word = |
michael@0 | 139 | '(?:' + |
michael@0 | 140 | $atom + // # Atom |
michael@0 | 141 | '|' + // # or |
michael@0 | 142 | $quoted_str + // # Quoted string |
michael@0 | 143 | ')' |
michael@0 | 144 | |
michael@0 | 145 | //# Item 12: domain-ref is just an atom |
michael@0 | 146 | $domain_ref = $atom; |
michael@0 | 147 | |
michael@0 | 148 | //# Item 13: domain-literal is like a quoted string, but [...] instead of "..." |
michael@0 | 149 | $domain_lit = |
michael@0 | 150 | $OpenBR + // # [ |
michael@0 | 151 | '(?:' + $dtext + '|' + $quoted_pair + ')*' + // # stuff |
michael@0 | 152 | $CloseBR; // # ] |
michael@0 | 153 | |
michael@0 | 154 | // # Item 9: sub-domain is a domain-ref or domain-literal |
michael@0 | 155 | $sub_domain = |
michael@0 | 156 | '(?:' + |
michael@0 | 157 | $domain_ref + |
michael@0 | 158 | '|' + |
michael@0 | 159 | $domain_lit + |
michael@0 | 160 | ')' + |
michael@0 | 161 | $X; // # optional trailing comments |
michael@0 | 162 | |
michael@0 | 163 | // # Item 6: domain is a list of subdomains separated by dots. |
michael@0 | 164 | $domain = |
michael@0 | 165 | $sub_domain + |
michael@0 | 166 | '(?:' + |
michael@0 | 167 | $Period + $X + $sub_domain + |
michael@0 | 168 | ')*'; |
michael@0 | 169 | |
michael@0 | 170 | //# Item 8: a route. A bunch of "@ $domain" separated by commas, followed by a colon. |
michael@0 | 171 | $route = |
michael@0 | 172 | '\@' + $X + $domain + |
michael@0 | 173 | '(?:,' + $X + '\@' + $X + $domain + ')*' + // # additional domains |
michael@0 | 174 | ':' + |
michael@0 | 175 | $X; // # optional trailing comments |
michael@0 | 176 | |
michael@0 | 177 | //# Item 6: local-part is a bunch of $word separated by periods |
michael@0 | 178 | $local_part = |
michael@0 | 179 | $word + $X |
michael@0 | 180 | '(?:' + |
michael@0 | 181 | $Period + $X + $word + $X + // # additional words |
michael@0 | 182 | ')*'; |
michael@0 | 183 | |
michael@0 | 184 | // # Item 2: addr-spec is local@domain |
michael@0 | 185 | $addr_spec = |
michael@0 | 186 | $local_part + '\@' + $X + $domain; |
michael@0 | 187 | |
michael@0 | 188 | //# Item 4: route-addr is <route? addr-spec> |
michael@0 | 189 | $route_addr = |
michael@0 | 190 | '<' + $X + // # < |
michael@0 | 191 | '(?:' + $route + ')?' + // # optional route |
michael@0 | 192 | $addr_spec + // # address spec |
michael@0 | 193 | '>'; // # > |
michael@0 | 194 | |
michael@0 | 195 | //# Item 3: phrase........ |
michael@0 | 196 | $phrase_ctrl = '\000-\010\012-\037'; // # like ctrl, but without tab |
michael@0 | 197 | |
michael@0 | 198 | //# Like atom-char, but without listing space, and uses phrase_ctrl. |
michael@0 | 199 | //# Since the class is negated, this matches the same as atom-char plus space and tab |
michael@0 | 200 | $phrase_char = |
michael@0 | 201 | '[^()<>\@,;:\".' + $esc + $OpenBR + $CloseBR + $NonASCII + $phrase_ctrl + ']'; |
michael@0 | 202 | |
michael@0 | 203 | // # We've worked it so that $word, $comment, and $quoted_str to not consume trailing $X |
michael@0 | 204 | // # because we take care of it manually. |
michael@0 | 205 | $phrase = |
michael@0 | 206 | $word + // # leading word |
michael@0 | 207 | $phrase_char + '*' + // # "normal" atoms and/or spaces |
michael@0 | 208 | '(?:' + |
michael@0 | 209 | '(?:' + $comment + '|' + $quoted_str + ')' + // # "special" comment or quoted string |
michael@0 | 210 | $phrase_char + '*' + // # more "normal" |
michael@0 | 211 | ')*'; |
michael@0 | 212 | |
michael@0 | 213 | // ## Item #1: mailbox is an addr_spec or a phrase/route_addr |
michael@0 | 214 | $mailbox = |
michael@0 | 215 | $X + // # optional leading comment |
michael@0 | 216 | '(?:' + |
michael@0 | 217 | $phrase + $route_addr + // # name and address |
michael@0 | 218 | '|' + // # or |
michael@0 | 219 | $addr_spec + // # address |
michael@0 | 220 | ')'; |
michael@0 | 221 | |
michael@0 | 222 | |
michael@0 | 223 | //########################################################################### |
michael@0 | 224 | |
michael@0 | 225 | |
michael@0 | 226 | re = new RegExp($mailbox, "g"); |
michael@0 | 227 | str = 'Jeffy<"That Tall Guy"@ora.com (this address is no longer active)>'; |
michael@0 | 228 | expect = Array('Jeffy<"That Tall Guy"@ora.com (this address is no longer active)>'); |
michael@0 | 229 | |
michael@0 | 230 | /* |
michael@0 | 231 | * Check performance - |
michael@0 | 232 | */ |
michael@0 | 233 | status = inSection(3); |
michael@0 | 234 | var start = new Date(); |
michael@0 | 235 | var result = re.exec(str); |
michael@0 | 236 | actual = elapsedTime(start); |
michael@0 | 237 | reportCompare(isThisFast(FAST), isThisFast(actual), status); |
michael@0 | 238 | |
michael@0 | 239 | /* |
michael@0 | 240 | * Check accuracy - |
michael@0 | 241 | */ |
michael@0 | 242 | status = inSection(4); |
michael@0 | 243 | testRegExp([status], [re], [str], [result], [expect]); |