Files
Tim van der Lippe 16b822804c Reland "Reland "Update stylelint to 14.0.1""
This reverts commit 2b4a9df2d9.

Reason for revert: subsequent presubmit uploads should be fixed now.

Original change's description:
> Revert "Reland "Update stylelint to 14.0.1""
>
> This reverts commit f2ea2c940d.
>
> Reason for revert: https://ci.chromium.org/ui/p/devtools-frontend/builders/try/dtf_presubmit_linux/b8831129368825517985/overview
>
> Original change's description:
> > Reland "Update stylelint to 14.0.1"
> >
> > This reverts commit 6c0f161c95.
> >
> > Reason for revert: the prerequisite CL (https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3259703) has landed
> >
> > Original change's description:
> > > Revert "Update stylelint to 14.0.1"
> > >
> > > This reverts commit 1e08ee816b.
> > >
> > > Reason for revert: tree is closed due to errors https://ci.chromium.org/ui/p/devtools-frontend/builders/ci/Stand-alone%20Linux/8169/overview
> > >
> > > Original change's description:
> > > > Update stylelint to 14.0.1
> > > >
> > > > This also upgrades PostCSS to 8.3.11.
> > > >
> > > > DISABLE_THIRD_PARTY_CHECK=Updating Stylelint configuration
> > > > R=​szuend@chromium.org
> > > >
> > > > Bug: none
> > > > Change-Id: I606540b03509d7c6e73f3d490327cd4174e03d31
> > > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3259541
> > > > Reviewed-by: Simon Zünd <szuend@chromium.org>
> > > > Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
> > >
> > > Bug: none
> > > Change-Id: Icb1c02b41dbccc3b4fc5760f5dd0b78eca078b61
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3263399
> > > Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> > > Owners-Override: Alex Rudenko <alexrudenko@chromium.org>
> > > Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
> >
> > DISABLE_THIRD_PARTY_CHECK=Updating Stylelint configuration
> >
> > Bug: none
> > Change-Id: If132a67ee4253d27114caedd66c5ee61c774a6c7
> > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3264206
> > Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
> > Reviewed-by: Simon Zünd <szuend@chromium.org>
> > Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
>
> Bug: none
> Change-Id: Idc6c9f5cc1e225c752799461eb0344e94b4ad1e5
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3264222
> Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>

DISABLE_THIRD_PARTY_CHECK=Updating Stylelint configuration

Bug: none
Change-Id: I609941d48b46bfcf454b03dcc75a76d460fbe674
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3264223
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
2021-11-08 14:47:39 +00:00

133 lines
4.0 KiB
JavaScript

/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
// It turns out that some (most?) JavaScript engines don't self-host
// `Array.prototype.sort`. This makes sense because C++ will likely remain
// faster than JS when doing raw CPU-intensive sorting. However, when using a
// custom comparator function, calling back and forth between the VM's C++ and
// JIT'd JS is rather slow *and* loses JIT type information, resulting in
// worse generated code for the comparator function than would be optimal. In
// fact, when sorting with a comparator, these costs outweigh the benefits of
// sorting in C++. By using our own JS-implemented Quick Sort (below), we get
// a ~3500ms mean speed-up in `bench/bench.html`.
function SortTemplate(comparator) {
/**
* Swap the elements indexed by `x` and `y` in the array `ary`.
*
* @param {Array} ary
* The array.
* @param {Number} x
* The index of the first item.
* @param {Number} y
* The index of the second item.
*/
function swap(ary, x, y) {
var temp = ary[x];
ary[x] = ary[y];
ary[y] = temp;
}
/**
* Returns a random integer within the range `low .. high` inclusive.
*
* @param {Number} low
* The lower bound on the range.
* @param {Number} high
* The upper bound on the range.
*/
function randomIntInRange(low, high) {
return Math.round(low + (Math.random() * (high - low)));
}
/**
* The Quick Sort algorithm.
*
* @param {Array} ary
* An array to sort.
* @param {function} comparator
* Function to use to compare two items.
* @param {Number} p
* Start index of the array
* @param {Number} r
* End index of the array
*/
function doQuickSort(ary, comparator, p, r) {
// If our lower bound is less than our upper bound, we (1) partition the
// array into two pieces and (2) recurse on each half. If it is not, this is
// the empty array and our base case.
if (p < r) {
// (1) Partitioning.
//
// The partitioning chooses a pivot between `p` and `r` and moves all
// elements that are less than or equal to the pivot to the before it, and
// all the elements that are greater than it after it. The effect is that
// once partition is done, the pivot is in the exact place it will be when
// the array is put in sorted order, and it will not need to be moved
// again. This runs in O(n) time.
// Always choose a random pivot so that an input array which is reverse
// sorted does not cause O(n^2) running time.
var pivotIndex = randomIntInRange(p, r);
var i = p - 1;
swap(ary, pivotIndex, r);
var pivot = ary[r];
// Immediately after `j` is incremented in this loop, the following hold
// true:
//
// * Every element in `ary[p .. i]` is less than or equal to the pivot.
//
// * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
for (var j = p; j < r; j++) {
if (comparator(ary[j], pivot, false) <= 0) {
i += 1;
swap(ary, i, j);
}
}
swap(ary, i + 1, j);
var q = i + 1;
// (2) Recurse on each half.
doQuickSort(ary, comparator, p, q - 1);
doQuickSort(ary, comparator, q + 1, r);
}
}
return doQuickSort;
}
function cloneSort(comparator) {
let template = SortTemplate.toString();
let templateFn = new Function(`return ${template}`)();
return templateFn(comparator);
}
/**
* Sort the given array in-place with the given comparator function.
*
* @param {Array} ary
* An array to sort.
* @param {function} comparator
* Function to use to compare two items.
*/
let sortCache = new WeakMap();
exports.quickSort = function (ary, comparator, start = 0) {
let doQuickSort = sortCache.get(comparator);
if (doQuickSort === void 0) {
doQuickSort = cloneSort(comparator);
sortCache.set(comparator, doQuickSort);
}
doQuickSort(ary, comparator, start, ary.length - 1);
};