Fixes mapValues runtime inefficiency in typescript-fetch (#21047)

* fixes mapValues runtime inefficiency in typescript-fetch

* adds regenerated typescript-fetch samples
This commit is contained in:
david-aeqium 2025-04-07 04:02:59 -04:00 committed by GitHub
parent 047ceeaa45
commit 63afd455f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 85 additions and 68 deletions

View File

@ -333,10 +333,11 @@ export function exists(json: any, key: string) {
{{^withoutRuntimeChecks}} {{^withoutRuntimeChecks}}
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
{{/withoutRuntimeChecks}} {{/withoutRuntimeChecks}}

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {

View File

@ -343,10 +343,11 @@ export function exists(json: any, key: string) {
} }
export function mapValues(data: any, fn: (item: any) => any) { export function mapValues(data: any, fn: (item: any) => any) {
return Object.keys(data).reduce( const result: { [key: string]: any } = {};
(acc, key) => ({ ...acc, [key]: fn(data[key]) }), for (const key of Object.keys(data)) {
{} result[key] = fn(data[key]);
); }
return result;
} }
export function canConsumeForm(consumes: Consume[]): boolean { export function canConsumeForm(consumes: Consume[]): boolean {