Skip to content

Commit 7f5fe4d

Browse files
Remove superficial .values() and .entries() calls (#3689)
Motivation: Spotted during investigation of unrelated issue. Maps and sets are iteratable, so no need to call these methods.
1 parent 62a08fa commit 7f5fe4d

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/execution/execute.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ function executeFieldsSerially(
391391
fields: Map<string, ReadonlyArray<FieldNode>>,
392392
): PromiseOrValue<ObjMap<unknown>> {
393393
return promiseReduce(
394-
fields.entries(),
394+
fields,
395395
(results, [responseName, fieldNodes]) => {
396396
const fieldPath = addPath(path, responseName, parentType.name);
397397
const result = executeField(
@@ -431,7 +431,7 @@ function executeFields(
431431
const results = Object.create(null);
432432
let containsPromise = false;
433433

434-
for (const [responseName, fieldNodes] of fields.entries()) {
434+
for (const [responseName, fieldNodes] of fields) {
435435
const fieldPath = addPath(path, responseName, parentType.name);
436436
const result = executeField(
437437
exeContext,
@@ -1227,7 +1227,9 @@ function executeSubscription(
12271227
rootType,
12281228
operation.selectionSet,
12291229
);
1230-
const [responseName, fieldNodes] = [...rootFields.entries()][0];
1230+
1231+
const firstRootField = rootFields.entries().next().value;
1232+
const [responseName, fieldNodes] = firstRootField;
12311233
const fieldName = fieldNodes[0].name.value;
12321234
const fieldDef = schema.getField(rootType, fieldName);
12331235

src/jsutils/__tests__/AccumulatorMap-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, it } from 'mocha';
44
import { AccumulatorMap } from '../AccumulatorMap';
55

66
function expectMap<K, V>(map: Map<K, V>) {
7-
return expect(Object.fromEntries(map.entries()));
7+
return expect(Object.fromEntries(map));
88
}
99

1010
describe('AccumulatorMap', () => {

src/jsutils/promiseForObject.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ import type { ObjMap } from './ObjMap';
1010
export function promiseForObject<T>(
1111
object: ObjMap<Promise<T>>,
1212
): Promise<ObjMap<T>> {
13-
return Promise.all(Object.values(object)).then((resolvedValues) => {
13+
const keys = Object.keys(object);
14+
const values = Object.values(object);
15+
16+
return Promise.all(values).then((resolvedValues) => {
1417
const resolvedObject = Object.create(null);
15-
for (const [i, key] of Object.keys(object).entries()) {
16-
resolvedObject[key] = resolvedValues[i];
18+
for (let i = 0; i < keys.length; ++i) {
19+
resolvedObject[keys[i]] = resolvedValues[i];
1720
}
1821
return resolvedObject;
1922
});

src/type/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function validateRootTypes(context: SchemaValidationContext): void {
144144
}
145145
}
146146

147-
for (const [rootType, operationTypes] of rootTypesMap.entries()) {
147+
for (const [rootType, operationTypes] of rootTypesMap) {
148148
if (operationTypes.length > 1) {
149149
const operationList = andList(operationTypes);
150150
context.reportError(

src/validation/rules/SingleFieldSubscriptionsRule.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ export function SingleFieldSubscriptionsRule(
6262
);
6363
}
6464
for (const fieldNodes of fields.values()) {
65-
const field = fieldNodes[0];
66-
const fieldName = field.name.value;
65+
const fieldName = fieldNodes[0].name.value;
6766
if (fieldName.startsWith('__')) {
6867
context.reportError(
6968
new GraphQLError(

0 commit comments

Comments
 (0)