Skip to content

Commit 295e3c7

Browse files
authored
Merge pull request #4249 from Tyriar/4241_fill
Remove fill polyfill
2 parents 02fa38c + d219da4 commit 295e3c7

File tree

7 files changed

+22
-131
lines changed

7 files changed

+22
-131
lines changed

addons/xterm-addon-unicode11/src/UnicodeV11.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import { IUnicodeVersionProvider } from 'xterm';
7-
import { fill } from 'common/TypedArrayUtils';
87

98
type CharWidth = 0 | 1 | 2;
109

@@ -198,15 +197,15 @@ export class UnicodeV11 implements IUnicodeVersionProvider {
198197
constructor() {
199198
if (!table) {
200199
table = new Uint8Array(65536);
201-
fill(table, 1);
200+
table.fill(1);
202201
table[0] = 0;
203-
fill(table, 0, 1, 32);
204-
fill(table, 0, 0x7f, 0xa0);
202+
table.fill(0, 1, 32);
203+
table.fill(0, 0x7f, 0xa0);
205204
for (let r = 0; r < BMP_COMBINING.length; ++r) {
206-
fill(table, 0, BMP_COMBINING[r][0], BMP_COMBINING[r][1] + 1);
205+
table.fill(0, BMP_COMBINING[r][0], BMP_COMBINING[r][1] + 1);
207206
}
208207
for (let r = 0; r < BMP_WIDE.length; ++r) {
209-
fill(table, 2, BMP_WIDE[r][0], BMP_WIDE[r][1] + 1);
208+
table.fill(2, BMP_WIDE[r][0], BMP_WIDE[r][1] + 1);
210209
}
211210
}
212211
}

addons/xterm-addon-webgl/src/GlyphRenderer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { createProgram, PROJECTION_MATRIX } from './WebglUtils';
77
import { IWebGL2RenderingContext, IWebGLVertexArrayObject, IRenderModel } from './Types';
8-
import { fill } from 'common/TypedArrayUtils';
98
import { NULL_CELL_CODE } from 'common/buffer/Constants';
109
import { Terminal } from 'xterm';
1110
import { IRasterizedGlyph, IRenderDimensions, ITextureAtlas } from 'browser/renderer/shared/Types';
@@ -225,7 +224,7 @@ export class GlyphRenderer extends Disposable {
225224
// Exit early if this is a null character, allow space character to continue as it may have
226225
// underline/strikethrough styles
227226
if (code === NULL_CELL_CODE || code === undefined/* This is used for the right side of wide chars */) {
228-
fill(array, 0, $i, $i + INDICES_PER_CELL - 1 - CELL_POSITION_INDICES);
227+
array.fill(0, $i, $i + INDICES_PER_CELL - 1 - CELL_POSITION_INDICES);
229228
return;
230229
}
231230

addons/xterm-addon-webgl/src/RenderModel.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import { IRenderModel } from './Types';
7-
import { fill } from 'common/TypedArrayUtils';
87
import { ISelectionRenderModel } from 'browser/renderer/shared/Types';
98
import { createSelectionRenderModel } from 'browser/renderer/shared/SelectionRenderModel';
109

@@ -35,7 +34,7 @@ export class RenderModel implements IRenderModel {
3534
}
3635

3736
public clear(): void {
38-
fill(this.cells, 0, 0);
39-
fill(this.lineLengths, 0, 0);
37+
this.cells.fill(0, 0);
38+
this.lineLengths.fill(0, 0);
4039
}
4140
}

src/common/TypedArrayUtils.test.ts

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @license MIT
44
*/
55
import { assert } from 'chai';
6-
import { fillFallback, concat } from 'common/TypedArrayUtils';
6+
import { concat } from 'common/TypedArrayUtils';
77

88
type TypedArray = Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array;
99

@@ -14,77 +14,6 @@ function deepEquals(a: TypedArray, b: TypedArray): void {
1414
}
1515
}
1616

17-
describe('polyfill conformance tests', function(): void {
18-
describe('TypedArray.fill', function(): void {
19-
it('should work with all typed array types', function(): void {
20-
const u81 = new Uint8Array(5);
21-
const u82 = new Uint8Array(5);
22-
deepEquals(fillFallback(u81, 2), u82.fill(2));
23-
deepEquals(fillFallback(u81, -1), u82.fill(-1));
24-
const u161 = new Uint16Array(5);
25-
const u162 = new Uint16Array(5);
26-
deepEquals(fillFallback(u161, 2), u162.fill(2));
27-
deepEquals(fillFallback(u161, 65535), u162.fill(65535));
28-
deepEquals(fillFallback(u161, -1), u162.fill(-1));
29-
const u321 = new Uint32Array(5);
30-
const u322 = new Uint32Array(5);
31-
deepEquals(fillFallback(u321, 2), u322.fill(2));
32-
deepEquals(fillFallback(u321, 65537), u322.fill(65537));
33-
deepEquals(fillFallback(u321, -1), u322.fill(-1));
34-
const i81 = new Int8Array(5);
35-
const i82 = new Int8Array(5);
36-
deepEquals(fillFallback(i81, 2), i82.fill(2));
37-
deepEquals(fillFallback(i81, -1), i82.fill(-1));
38-
const i161 = new Int16Array(5);
39-
const i162 = new Int16Array(5);
40-
deepEquals(fillFallback(i161, 2), i162.fill(2));
41-
deepEquals(fillFallback(i161, 65535), i162.fill(65535));
42-
deepEquals(fillFallback(i161, -1), i162.fill(-1));
43-
const i321 = new Int32Array(5);
44-
const i322 = new Int32Array(5);
45-
deepEquals(fillFallback(i321, 2), i322.fill(2));
46-
deepEquals(fillFallback(i321, 65537), i322.fill(65537));
47-
deepEquals(fillFallback(i321, -1), i322.fill(-1));
48-
const f321 = new Float32Array(5);
49-
const f322 = new Float32Array(5);
50-
deepEquals(fillFallback(f321, 1.2345), f322.fill(1.2345));
51-
const f641 = new Float64Array(5);
52-
const f642 = new Float64Array(5);
53-
deepEquals(fillFallback(f641, 1.2345), f642.fill(1.2345));
54-
const u8Clamped1 = new Uint8ClampedArray(5);
55-
const u8Clamped2 = new Uint8ClampedArray(5);
56-
deepEquals(fillFallback(u8Clamped1, 2), u8Clamped2.fill(2));
57-
deepEquals(fillFallback(u8Clamped1, 257), u8Clamped2.fill(257));
58-
});
59-
it('start offset', function(): void {
60-
for (let i = -2; i < 10; ++i) {
61-
const u81 = new Uint8Array(5);
62-
const u83 = new Uint8Array(5);
63-
deepEquals(fillFallback(u81, 2, i), u83.fill(2, i));
64-
deepEquals(fillFallback(u81, -1, i), u83.fill(-1, i));
65-
}
66-
});
67-
it('end offset', function(): void {
68-
for (let i = -2; i < 10; ++i) {
69-
const u81 = new Uint8Array(5);
70-
const u83 = new Uint8Array(5);
71-
deepEquals(fillFallback(u81, 2, 0, i), u83.fill(2, 0, i));
72-
deepEquals(fillFallback(u81, -1, 0, i), u83.fill(-1, 0, i));
73-
}
74-
});
75-
it('start/end offset', function(): void {
76-
for (let i = -2; i < 10; ++i) {
77-
for (let j = -2; j < 10; ++j) {
78-
const u81 = new Uint8Array(5);
79-
const u83 = new Uint8Array(5);
80-
deepEquals(fillFallback(u81, 2, i, j), u83.fill(2, i, j));
81-
deepEquals(fillFallback(u81, -1, i, j), u83.fill(-1, i, j));
82-
}
83-
}
84-
});
85-
});
86-
});
87-
8817
describe('typed array convenience functions', () => {
8918
it('concat', () => {
9019
const a = new Uint8Array([1, 2, 3, 4, 5]);

src/common/TypedArrayUtils.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,6 @@
55

66
export type TypedArray = Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array;
77

8-
9-
/**
10-
* polyfill for TypedArray.fill
11-
* This is needed to support .fill in all safari versions and IE 11.
12-
*/
13-
export function fill<T extends TypedArray>(array: T, value: number, start?: number, end?: number): T {
14-
// all modern engines that support .fill
15-
if (array.fill) {
16-
return array.fill(value, start, end) as T;
17-
}
18-
return fillFallback(array, value, start, end);
19-
}
20-
21-
export function fillFallback<T extends TypedArray>(array: T, value: number, start: number = 0, end: number = array.length): T {
22-
// safari and IE 11
23-
// since IE 11 does not support Array.prototype.fill either
24-
// we cannot use the suggested polyfill from MDN
25-
// instead we simply fall back to looping
26-
if (start >= array.length) {
27-
return array;
28-
}
29-
start = (array.length + start) % array.length;
30-
if (end >= array.length) {
31-
end = array.length;
32-
} else {
33-
end = (array.length + end) % array.length;
34-
}
35-
for (let i = start; i < end; ++i) {
36-
array[i] = value;
37-
}
38-
return array;
39-
}
40-
418
/**
429
* Concat two typed arrays `a` and `b`.
4310
* Returns a new typed array.

src/common/input/UnicodeV6.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @license MIT
44
*/
55
import { IUnicodeVersionProvider } from 'common/services/Services';
6-
import { fill } from 'common/TypedArrayUtils';
76

87
type CharWidth = 0 | 1 | 2;
98

@@ -90,34 +89,34 @@ export class UnicodeV6 implements IUnicodeVersionProvider {
9089
// init lookup table once
9190
if (!table) {
9291
table = new Uint8Array(65536);
93-
fill(table, 1);
92+
table.fill(1);
9493
table[0] = 0;
9594
// control chars
96-
fill(table, 0, 1, 32);
97-
fill(table, 0, 0x7f, 0xa0);
95+
table.fill(0, 1, 32);
96+
table.fill(0, 0x7f, 0xa0);
9897

9998
// apply wide char rules first
10099
// wide chars
101-
fill(table, 2, 0x1100, 0x1160);
100+
table.fill(2, 0x1100, 0x1160);
102101
table[0x2329] = 2;
103102
table[0x232a] = 2;
104-
fill(table, 2, 0x2e80, 0xa4d0);
103+
table.fill(2, 0x2e80, 0xa4d0);
105104
table[0x303f] = 1; // wrongly in last line
106105

107-
fill(table, 2, 0xac00, 0xd7a4);
108-
fill(table, 2, 0xf900, 0xfb00);
109-
fill(table, 2, 0xfe10, 0xfe1a);
110-
fill(table, 2, 0xfe30, 0xfe70);
111-
fill(table, 2, 0xff00, 0xff61);
112-
fill(table, 2, 0xffe0, 0xffe7);
106+
table.fill(2, 0xac00, 0xd7a4);
107+
table.fill(2, 0xf900, 0xfb00);
108+
table.fill(2, 0xfe10, 0xfe1a);
109+
table.fill(2, 0xfe30, 0xfe70);
110+
table.fill(2, 0xff00, 0xff61);
111+
table.fill(2, 0xffe0, 0xffe7);
113112

114113
// apply combining last to ensure we overwrite
115114
// wrongly wide set chars:
116115
// the original algo evals combining first and falls
117116
// through to wide check so we simply do here the opposite
118117
// combining 0
119118
for (let r = 0; r < BMP_COMBINING.length; ++r) {
120-
fill(table, 0, BMP_COMBINING[r][0], BMP_COMBINING[r][1] + 1);
119+
table.fill(0, BMP_COMBINING[r][0], BMP_COMBINING[r][1] + 1);
121120
}
122121
}
123122
}

src/common/parser/EscapeSequenceParser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { IParsingState, IDcsHandler, IEscapeSequenceParser, IParams, IOscHandler
77
import { ParserState, ParserAction } from 'common/parser/Constants';
88
import { Disposable, toDisposable } from 'common/Lifecycle';
99
import { IDisposable } from 'common/Types';
10-
import { fill } from 'common/TypedArrayUtils';
1110
import { Params } from 'common/parser/Params';
1211
import { OscParser } from 'common/parser/OscParser';
1312
import { DcsParser } from 'common/parser/DcsParser';
@@ -39,7 +38,7 @@ export class TransitionTable {
3938
* @param next default next state
4039
*/
4140
public setDefault(action: ParserAction, next: ParserState): void {
42-
fill(this.table, action << TableAccess.TRANSITION_ACTION_SHIFT | next);
41+
this.table.fill(action << TableAccess.TRANSITION_ACTION_SHIFT | next);
4342
}
4443

4544
/**

0 commit comments

Comments
 (0)