Skip to content

Commit 63afd45

Browse files
authored
Fixes mapValues runtime inefficiency in typescript-fetch (#21047)
* fixes mapValues runtime inefficiency in typescript-fetch * adds regenerated typescript-fetch samples
1 parent 047ceea commit 63afd45

File tree

17 files changed

+85
-68
lines changed

17 files changed

+85
-68
lines changed

modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache

+5-4
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,11 @@ export function exists(json: any, key: string) {
333333

334334
{{^withoutRuntimeChecks}}
335335
export function mapValues(data: any, fn: (item: any) => any) {
336-
return Object.keys(data).reduce(
337-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
338-
{}
339-
);
336+
const result: { [key: string]: any } = {};
337+
for (const key of Object.keys(data)) {
338+
result[key] = fn(data[key]);
339+
}
340+
return result;
340341
}
341342
{{/withoutRuntimeChecks}}
342343

samples/client/others/typescript-fetch/self-import-issue/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/default/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/enum/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
343343
}
344344

345345
export function mapValues(data: any, fn: (item: any) => any) {
346-
return Object.keys(data).reduce(
347-
(acc, key) => ({ ...acc, [key]: fn(data[key]) }),
348-
{}
349-
);
346+
const result: { [key: string]: any } = {};
347+
for (const key of Object.keys(data)) {
348+
result[key] = fn(data[key]);
349+
}
350+
return result;
350351
}
351352

352353
export function canConsumeForm(consumes: Consume[]): boolean {

0 commit comments

Comments
 (0)