Skip to content

Commit ed89e69

Browse files
Merge pull request #73 from pmndrs/code-quality
Merging this now, will update NPM later on this week.
2 parents 8f0b6bb + f25f7d1 commit ed89e69

File tree

7 files changed

+18
-22
lines changed

7 files changed

+18
-22
lines changed

scripts/update_benchmarks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ const outputFile = async (name: string, content: any) => {
4646
.map((benchmark) => {
4747
benchmark.gpu = benchmark.gpu
4848
.toLowerCase()
49-
.replace(/\s*\([^\)]+(\))/g, '')
50-
.replace(/([0-9]+)\/[^ ]+/, '$1')
49+
.replace(/\s*\([^)]+(\))/g, '')
50+
.replace(/(\d+)\/[^ ]+/, '$1')
5151
.replace(
5252
/x\.org |inc\. |open source technology center |imagination technologies | |nvidia corporation |apple inc\. |advanced micro devices, inc\. | series$| edition$| graphics$/g,
5353
''
@@ -99,7 +99,7 @@ const outputFile = async (name: string, content: any) => {
9999
fps:
100100
fpses[index] === ''
101101
? undefined
102-
: Math.round(Number(fpses[index].replace(/[^0-9.]+/g, ''))),
102+
: Math.round(Number(fpses[index].replace(/[^\d.]+/g, ''))),
103103
gpu: gpuNameLookup[gpuIndex],
104104
mobile: formFactorLookup[formFactor[index]].includes('mobile'),
105105
resolution: screenSizeLookup[screenSizes[index]],

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const getGPUTier = async ({
126126
? (['adreno', 'apple', 'mali-t', 'mali', 'nvidia', 'powervr'] as const)
127127
: (['intel', 'amd', 'radeon', 'nvidia', 'geforce'] as const);
128128
for (const type of types) {
129-
if (renderer.indexOf(type) > -1) {
129+
if (renderer.includes(type)) {
130130
return type;
131131
}
132132
}
@@ -168,7 +168,7 @@ export const getGPUTier = async ({
168168

169169
// If nothing matched, try comparing model names:
170170
if (!matched.length) {
171-
matched = benchmarks.filter(([model]) => model.indexOf(renderer) > -1);
171+
matched = benchmarks.filter(([model]) => model.includes(renderer));
172172

173173
debug?.(
174174
`found ${matched.length} matching entries comparing model names`,
@@ -229,7 +229,7 @@ export const getGPUTier = async ({
229229
}
230230

231231
if (!closest) {
232-
return undefined;
232+
return;
233233
}
234234

235235
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -287,10 +287,10 @@ export const getGPUTier = async ({
287287
);
288288

289289
if (!results.length) {
290-
const blocklistedModel: string | undefined = BLOCKLISTED_GPUS.filter(
290+
const blocklistedModel: string | undefined = BLOCKLISTED_GPUS.find(
291291
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
292-
(blocklistedModel) => renderer!.indexOf(blocklistedModel) > -1
293-
)[0];
292+
(blocklistedModel) => renderer!.includes(blocklistedModel)
293+
);
294294
return blocklistedModel
295295
? toResult(0, 'BLOCKLISTED', blocklistedModel)
296296
: toResult(1, 'FALLBACK', `${renderer} (${rawRenderer})`);

src/internal/cleanRenderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ export const cleanRenderer = (renderer: string) => {
77
.toLowerCase()
88
// Strip off ANGLE() - for example:
99
// 'ANGLE (NVIDIA TITAN Xp)' becomes 'NVIDIA TITAN Xp'':
10-
.replace(/angle \((.+)\)*$/, '$1')
10+
.replace(/^angle ?\((.+)\)*$/, '$1')
1111
// Strip off [number]gb & strip off direct3d and after - for example:
1212
// 'Radeon (TM) RX 470 Series Direct3D11 vs_5_0 ps_5_0' becomes
1313
// 'Radeon (TM) RX 470 Series'
14-
.replace(/\s+([0-9]+gb|direct3d.+$)|\(r\)| \([^)]+\)$/g, '');
14+
.replace(/\s(\d{1,2}gb|direct3d.+$)|\(r\)| \([^)]+\)$/g, '');
1515

1616
debug?.('cleanRenderer - renderer cleaned to', { renderer });
1717

src/internal/deobfuscateAppleGPU.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const deobfuscateAppleGPU = (
8282
gl.vertexAttribPointer(aPosition, 3, GL_FLOAT, false, 0, 0);
8383
gl.enableVertexAttribArray(aPosition);
8484

85-
gl.clearColor(1.0, 1.0, 1.0, 1.0);
85+
gl.clearColor(1, 1, 1, 1);
8686
gl.clear(GL_COLOR_BUFFER_BIT);
8787
gl.viewport(0, 0, 1, 1);
8888
gl.drawArrays(GL_TRIANGLES, 0, 3);

src/internal/deobfuscateRenderer.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,5 @@ export const deobfuscateRenderer = (
66
renderer: string,
77
isMobileTier: boolean
88
) => {
9-
if (renderer === 'apple gpu') {
10-
return deobfuscateAppleGPU(gl, renderer, isMobileTier);
11-
} else {
12-
return [renderer];
13-
}
9+
return renderer === 'apple gpu' ? deobfuscateAppleGPU(gl, renderer, isMobileTier) : [renderer];
1410
};

src/internal/getGPUVersion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ export const getGPUVersion = (model: string) => {
33

44
const matches =
55
// First set of digits
6-
model.match(/[\d]+/) ||
6+
model.match(/\d+/) ||
77
// If the renderer did not contain any numbers, match letters
8-
model.match(/(\W|^)([a-zA-Z]{1,3})(\W|$)/g);
8+
model.match(/(\W|^)([A-Za-z]{1,3})(\W|$)/g);
99

1010
// Remove any non-word characters and also remove 'amd' which could be matched
1111
// in the clause above

test/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async () => {
8080
});
8181

8282
// expect BENCHMARK results:
83-
[
83+
for (const { input, expected } of [
8484
{
8585
expected: {
8686
gpu: 'intel uhd graphics 620',
@@ -233,7 +233,7 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async () => {
233233
renderer: 'Mali-G51',
234234
},
235235
},
236-
].forEach(({ input, expected }) => {
236+
]) {
237237
test(`${input.renderer} should find ${expected.gpu}`, async () => {
238238
expectGPUResults(
239239
{
@@ -243,7 +243,7 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async () => {
243243
await getTier(input)
244244
);
245245
});
246-
});
246+
}
247247

248248
// expect FALLBACK results:
249249
[

0 commit comments

Comments
 (0)