Skip to content

Commit

Permalink
refactor: update all countdown loops
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Nov 8, 2021
1 parent b20f99f commit a5f374b
Show file tree
Hide file tree
Showing 112 changed files with 170 additions and 170 deletions.
4 changes: 2 additions & 2 deletions examples/hdom-canvas-particles/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const initCurves = () => [
];

const updateCurves = (curves: Cubic[], t: number) => {
for (let i = curves.length; --i >= 0; ) {
for (let i = curves.length; i-- > 0; ) {
const crv = curves[i];
const pts = crv.points;
const id = crv.attribs!.id;
Expand All @@ -57,7 +57,7 @@ const makeParticle = (curves: Cubic[]) => ({
});

const updateParticles = (particles: Particle[]) => {
for (let i = particles.length; --i >= 0; ) {
for (let i = particles.length; i-- > 0; ) {
const p = particles[i];
p.pos = wrap01(p.pos + p.vel);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/hdom-local-render/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class LocalReRenderable {
localRender(...args: any[]) {
const el = this.el!;
const children = el.parentElement!.children;
for (let i = children.length; --i >= 0; ) {
for (let i = children.length; i-- > 0; ) {
if (children[i] === el) {
replaceChild(
{},
Expand Down
2 changes: 1 addition & 1 deletion examples/imgui-basics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const smoothedVolume = tweenNumber(volume, 0, 0.2);

// derived view for slider label
const volumeLabel = smoothedVolume.map((x) => {
for (let i = PRESETS.length; --i >= 0; ) {
for (let i = PRESETS.length; i-- > 0; ) {
if (x >= PRESETS[i][1]) return `${Math.round(x)} (${PRESETS[i][0]})`;
}
return "";
Expand Down
2 changes: 1 addition & 1 deletion examples/pixel-sorting/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const pixelSortBuffer = (
const { pixels, width, height } = buf;
const row = closedOpen(0, width);
const column = closedOpen(0, height);
for (let i = iter; --i >= 0; ) {
for (let i = iter; i-- > 0; ) {
const num = SYSTEM.minmax(min, max) | 0;
const n2 = num >> 1;
// random start/pixel position in image
Expand Down
2 changes: 1 addition & 1 deletion examples/xml-converter/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ format.add("obj", (opts, res, x) => {
} else {
const outer = spaces(opts.indent);
res += opts.prefix + "{" + opts.lineSep;
for (let i = keys.length; --i >= 0; ) {
for (let i = keys.length; i-- > 0; ) {
const k = keys[i];
res += formatPair(
k === "style"
Expand Down
2 changes: 1 addition & 1 deletion packages/adjacency/src/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class AdjacencyBitMatrix implements IGraph<number> {

*edges() {
const directed = !this.undirected;
for (let i = this.mat.n; --i >= 0; ) {
for (let i = this.mat.n; i-- > 0; ) {
for (let n of this.neighbors(i)) {
if (directed || n > i) {
yield <Edge>[i, n];
Expand Down
2 changes: 1 addition & 1 deletion packages/adjacency/src/disjoint-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class DisjointSet {
subsets() {
const sets: Map<number, number[]> = new Map();
const roots = this.roots;
for (let i = roots.length; --i >= 0; ) {
for (let i = roots.length; i-- > 0; ) {
const id = this.canonical(i);
const s = sets.get(id);
if (s) {
Expand Down
6 changes: 3 additions & 3 deletions packages/adjacency/src/sparse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ export class AdjacencyMatrix extends CSR implements IGraph<number> {
switch (deg) {
case "out":
default:
for (let i = this.m; --i >= 0; ) {
for (let i = this.m; i-- > 0; ) {
res.setAt(i, i, this.nnzRow(i));
}
break;
case "in":
for (let i = this.m; --i >= 0; ) {
for (let i = this.m; i-- > 0; ) {
res.setAt(i, i, this.nnzCol(i));
}
break;
case "inout":
for (let i = this.m; --i >= 0; ) {
for (let i = this.m; i-- > 0; ) {
res.setAt(i, i, this.nnzRow(i) + this.nnzCol(i));
}
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/mixins/inotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const INotifyMixin = mixin(<INotify>{

__listener(listeners: [Listener, any][], f: Listener, scope: any) {
let i = listeners.length;
while (--i >= 0) {
while (i-- > 0) {
const l = listeners[i];
if (l[0] === f && l[1] === scope) {
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/arrays/src/ends-with.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export const endsWith = <T>(
let i = buf.length;
let j = needle.length;
if (i < j) return false;
while ((--i, --j >= 0 && equiv(buf[i], needle[j]))) {}
while ((--i, j-- > 0 && equiv(buf[i], needle[j]))) {}
return j < 0;
};
2 changes: 1 addition & 1 deletion packages/arrays/src/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const findIndex = <T>(
x: T,
equiv: Predicate2<T> = _equiv
) => {
for (let i = buf.length; --i >= 0; ) {
for (let i = buf.length; i-- > 0; ) {
if (equiv(x, buf[i])) return i;
}
return -1;
Expand Down
2 changes: 1 addition & 1 deletion packages/arrays/src/shuffle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const shuffleRange = <T extends AnyArray>(
let n = end - start;
const l = n;
if (l > 1) {
while (--n >= 0) {
while (n-- > 0) {
const a = (start + rnd.float(l)) | 0;
const b = (start + rnd.float(l)) | 0;
const t = buf[a];
Expand Down
2 changes: 1 addition & 1 deletion packages/arrays/src/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const multiSwap = (...xs: AnyArray[]): SwapFn => {
default:
return (a, x, y) => {
swap(a, x, y);
for (let i = n; --i >= 0; ) swap(xs[i], x, y);
for (let i = n; i-- > 0; ) swap(xs[i], x, y);
};
}
};
2 changes: 1 addition & 1 deletion packages/arrays/src/swizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const swizzle = <T>(order: string | PropertyKey[]): Fn<T, any[]> => {
default:
return (x: any) => {
const res = [];
for (let i = order.length; --i >= 0; ) {
for (let i = order.length; i-- > 0; ) {
res[i] = x[order[i]];
}
return res;
Expand Down
4 changes: 2 additions & 2 deletions packages/associative/src/array-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class ArraySet<T> extends Set<T> implements IEquivSet<T> {

delete(key: T) {
const { equiv, vals } = __private.get(this)!;
for (let i = vals.length; --i >= 0; ) {
for (let i = vals.length; i-- > 0; ) {
if (equiv(vals[i], key)) {
vals.splice(i, 1);
return true;
Expand All @@ -131,7 +131,7 @@ export class ArraySet<T> extends Set<T> implements IEquivSet<T> {
*/
forEach(fn: Fn3<T, T, Set<T>, void>, thisArg?: any) {
const vals = __vals(this);
for (let i = vals.length; --i >= 0; ) {
for (let i = vals.length; i-- > 0; ) {
const v = vals[i];
fn.call(thisArg, v, v, this);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/associative/src/sorted-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class SortedMap<K, V> extends Map<K, V> {
if (node.next[level] && code === 0) {
do {
node.next[level].v = v;
} while (--level >= 0);
} while (level-- > 0);
return this;
}
stack[level--] = node;
Expand Down
2 changes: 1 addition & 1 deletion packages/associative/src/sparse-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export abstract class ASparseSet<T extends UIntArray>
}
const $this = __private.get(this)!;
const d = $this.dense;
for (let i = $this.n; --i >= 0; ) {
for (let i = $this.n; i-- > 0; ) {
if (!o.has(d[i])) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/base-n/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class BaseN implements IBase {
let y = this.decodeBigInt(x);
const M = BigInt(255);
const SHIFT = BigInt(8);
for (let i = buf.length; --i >= 0; ) {
for (let i = buf.length; i-- > 0; ) {
buf[i] = Number(y & M);
y >>= SHIFT;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bench/src/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const benchmark = (
const t = benchResult(fn, warmup * size)[1];
output && outputString(format!.warmup(t, _opts));
const samples: number[] = [];
for (let i = iter!; --i >= 0; ) {
for (let i = iter!; i-- > 0; ) {
samples.push(benchResult(fn, size)[1]);
}
samples.sort((a, b) => a - b);
Expand Down
2 changes: 1 addition & 1 deletion packages/bencode/src/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const readFloat = (iter: Iterator<number>) => {
const readBytes = (iter: Iterator<number>, len: number) => {
let i: IteratorResult<number>;
let buf: number[] = [];
while (--len >= 0 && !(i = iter.next()).done) {
while (len-- > 0 && !(i = iter.next()).done) {
buf.push(i.value);
}
return len < 0 ? buf : illegalState(`expected string, reached EOF`);
Expand Down
2 changes: 1 addition & 1 deletion packages/bitfield/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const binOp = (
src: Uint32Array,
op: Fn2<number, number, number>
) => {
for (let i = src.length; --i >= 0; ) dest[i] = op(src[i], dest[i]);
for (let i = src.length; i-- > 0; ) dest[i] = op(src[i], dest[i]);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/bitstream/src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class BitInputStream {

readWords(n: number, wordSize = 8) {
let out = [];
while (--n >= 0) {
while (n-- > 0) {
out.push(this.read(wordSize));
}
return out;
Expand Down
2 changes: 1 addition & 1 deletion packages/color/src/color-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function* colorsFromRange(
opts: Partial<ColorRangeOpts> = {}
) {
let num = opts.num != undefined ? opts.num : Infinity;
while (--num >= 0) yield colorFromRange(range, opts);
while (num-- > 0) yield colorFromRange(range, opts);
}

/** @internal */
Expand Down
2 changes: 1 addition & 1 deletion packages/compose/src/juxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function juxt<T>(...fns: Fn<any, any>[]) {
default:
return (x: T) => {
let res = new Array(fns.length);
for (let i = fns.length; --i >= 0; ) {
for (let i = fns.length; i-- > 0; ) {
res[i] = fns[i](x);
}
return res;
Expand Down
4 changes: 2 additions & 2 deletions packages/diff/src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const buildFullLog = <T>(
aID = 1;
dID = -1;
}
for (; --i >= 0; ) {
for (; i-- > 0; ) {
const e = epc[i];
const ppx = pathPos[e];
const ppy = pathPos[e + 1];
Expand Down Expand Up @@ -235,7 +235,7 @@ const buildLinearLog = <T>(
let i = epc.length,
px = 0,
py = 0;
for (; --i >= 0; ) {
for (; i-- > 0; ) {
const e = epc[i];
const ppx = pathPos[e];
const ppy = pathPos[e + 1];
Expand Down
4 changes: 2 additions & 2 deletions packages/dsp/src/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class Delay<T> extends AProc<T, T> implements IClear, ILength, IReset {
clear() {
const { _buf, _empty } = this;
if (isFunction(_empty)) {
for (let i = _buf.length; --i >= 0; ) {
for (let i = _buf.length; i-- > 0; ) {
this._buf[i] = _empty();
}
} else {
Expand Down Expand Up @@ -92,7 +92,7 @@ export class Delay<T> extends AProc<T, T> implements IClear, ILength, IReset {
* returns it.
*/
multiTap(t: ArrayLike<number>, out: T[] = []) {
for (let i = t.length; --i >= 0; ) {
for (let i = t.length; i-- > 0; ) {
out[i] = this.tap(t[i]);
}
return out;
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/fft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const transform = (real: NumericArray, img: NumericArray, n: number) => {
let ur: number, ui: number;
let wr: number, wi: number;
let t: number;
for (let b = Math.ceil(Math.log2(n)); --b >= 0; ) {
for (let b = Math.ceil(Math.log2(n)); b-- > 0; ) {
prevStep = step;
step <<= 1;
ur = 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/filter-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const freqRange: FnU3<number, number[]> = (fstart, fend, num) =>
const convolve = (coeffs: NumericArray, w0: number) => {
let c = 0;
let s = 0;
for (let i = coeffs.length; --i >= 0; ) {
for (let i = coeffs.length; i-- > 0; ) {
const k = cossin(w0 * i, coeffs[i]);
c += k[0];
s += k[1];
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/internal/take.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const __take = <T>(
out: T[] = [],
idx = 0
) => {
for (; --num >= 0; ) {
for (; num-- > 0; ) {
out[idx++] = src.next();
}
return out;
Expand Down
8 changes: 4 additions & 4 deletions packages/dsp/src/power.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isComplex } from "./complex.js";
*/
export const integralT = (window: NumericArray) => {
let sum = 0;
for (let i = window.length; --i >= 0; ) {
for (let i = window.length; i-- > 0; ) {
sum += window[i];
}
return sum;
Expand All @@ -23,7 +23,7 @@ export const integralT = (window: NumericArray) => {
*/
export const integralTSquared = (window: NumericArray) => {
let sum = 0;
for (let i = window.length; --i >= 0; ) {
for (let i = window.length; i-- > 0; ) {
sum += window[i] ** 2;
}
return sum;
Expand All @@ -36,7 +36,7 @@ export const integralTSquared = (window: NumericArray) => {
*/
export const integralF = ([real, img]: ComplexArray) => {
let sum = 0;
for (let i = real.length; --i >= 0; ) {
for (let i = real.length; i-- > 0; ) {
sum += Math.hypot(real[i], img[i]);
}
return sum;
Expand All @@ -49,7 +49,7 @@ export const integralF = ([real, img]: ComplexArray) => {
*/
export const integralFSquared = ([real, img]: ComplexArray) => {
let sum = 0;
for (let i = real.length; --i >= 0; ) {
for (let i = real.length; i-- > 0; ) {
sum += real[i] ** 2 + img[i] ** 2;
}
return sum;
Expand Down
2 changes: 1 addition & 1 deletion packages/dsp/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const applyWindow = (
window: NumericArray,
out = signal
) => {
for (let i = signal.length; --i >= 0; ) {
for (let i = signal.length; i-- > 0; ) {
out[i] = signal[i] * window[i];
}
return out;
Expand Down
Loading

0 comments on commit a5f374b

Please sign in to comment.