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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | // Shared utility functions for and macros parallel operations in `Array.js` |
michael@0 | 6 | // and `TypedObject.js`. |
michael@0 | 7 | |
michael@0 | 8 | #ifdef ENABLE_PARALLEL_JS |
michael@0 | 9 | |
michael@0 | 10 | /* The mode asserts options object. */ |
michael@0 | 11 | #define TRY_PARALLEL(MODE) \ |
michael@0 | 12 | ((!MODE || MODE.mode !== "seq")) |
michael@0 | 13 | #define ASSERT_SEQUENTIAL_IS_OK(MODE) \ |
michael@0 | 14 | do { if (MODE) AssertSequentialIsOK(MODE) } while(false) |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * The ParallelSpew intrinsic is only defined in debug mode, so define a dummy |
michael@0 | 18 | * if debug is not on. |
michael@0 | 19 | */ |
michael@0 | 20 | #ifndef DEBUG |
michael@0 | 21 | #define ParallelSpew(args) |
michael@0 | 22 | #endif |
michael@0 | 23 | |
michael@0 | 24 | #define MAX_SLICE_SHIFT 6 |
michael@0 | 25 | #define MAX_SLICE_SIZE 64 |
michael@0 | 26 | #define MAX_SLICES_PER_WORKER 8 |
michael@0 | 27 | |
michael@0 | 28 | /** |
michael@0 | 29 | * Macros to help compute the start and end indices of slices based on id. Use |
michael@0 | 30 | * with the object returned by ComputeSliceInfo. |
michael@0 | 31 | */ |
michael@0 | 32 | #define SLICE_START_INDEX(shift, id) \ |
michael@0 | 33 | (id << shift) |
michael@0 | 34 | #define SLICE_END_INDEX(shift, start, length) \ |
michael@0 | 35 | std_Math_min(start + (1 << shift), length) |
michael@0 | 36 | |
michael@0 | 37 | /** |
michael@0 | 38 | * ForkJoinGetSlice acts as identity when we are not in a parallel section, so |
michael@0 | 39 | * pass in the next sequential value when we are in sequential mode. The |
michael@0 | 40 | * reason for this odd API is because intrinsics *need* to be called during |
michael@0 | 41 | * ForkJoin's warmup to fill the TI info. |
michael@0 | 42 | */ |
michael@0 | 43 | #define GET_SLICE(sliceStart, sliceEnd, id) \ |
michael@0 | 44 | ((id = ForkJoinGetSlice((InParallelSection() ? -1 : sliceStart++) | 0)) < sliceEnd) |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * Determine the number and size of slices. The info object has the following |
michael@0 | 48 | * properties: |
michael@0 | 49 | * |
michael@0 | 50 | * - shift: amount to shift by to compute indices |
michael@0 | 51 | * - count: number of slices |
michael@0 | 52 | */ |
michael@0 | 53 | function ComputeSlicesInfo(length) { |
michael@0 | 54 | var count = length >>> MAX_SLICE_SHIFT; |
michael@0 | 55 | var numWorkers = ForkJoinNumWorkers(); |
michael@0 | 56 | if (count < numWorkers) |
michael@0 | 57 | count = numWorkers; |
michael@0 | 58 | else if (count >= numWorkers * MAX_SLICES_PER_WORKER) |
michael@0 | 59 | count = numWorkers * MAX_SLICES_PER_WORKER; |
michael@0 | 60 | |
michael@0 | 61 | // Round the slice size to be a power of 2. |
michael@0 | 62 | var shift = std_Math_max(std_Math_log2(length / count) | 0, 1); |
michael@0 | 63 | |
michael@0 | 64 | // Recompute count with the rounded size. |
michael@0 | 65 | count = length >>> shift; |
michael@0 | 66 | if (count << shift !== length) |
michael@0 | 67 | count += 1; |
michael@0 | 68 | |
michael@0 | 69 | return { shift: shift, count: count }; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | #endif // ENABLE_PARALLEL_JS |