From cde5917f658db631d44faa804d8e52d8eed8bd50 Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Fri, 9 Feb 2024 22:13:59 +0900 Subject: [PATCH] perf: remove redundant operation in FormData --- lib/core/util.js | 8 +------- lib/fetch/formdata.js | 11 ++++------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/core/util.js b/lib/core/util.js index 55bf9f49822..7b863067870 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -438,13 +438,7 @@ const hasToWellFormed = !!String.prototype.toWellFormed * @param {string} val */ function toUSVString (val) { - if (hasToWellFormed) { - return `${val}`.toWellFormed() - } else if (nodeUtil.toUSVString) { - return nodeUtil.toUSVString(val) - } - - return `${val}` + return hasToWellFormed ? `${val}`.toWellFormed() : nodeUtil.toUSVString(val) } /** diff --git a/lib/fetch/formdata.js b/lib/fetch/formdata.js index b519f890b18..add64aa9226 100644 --- a/lib/fetch/formdata.js +++ b/lib/fetch/formdata.js @@ -1,6 +1,6 @@ 'use strict' -const { isBlobLike, toUSVString, makeIterator } = require('./util') +const { isBlobLike, makeIterator } = require('./util') const { kState } = require('./symbols') const { kEnumerableProperty } = require('../core/util') const { File: UndiciFile, FileLike, isFileLike } = require('./file') @@ -133,7 +133,7 @@ class FormData { ? webidl.converters.Blob(value, { strict: false }) : webidl.converters.USVString(value) filename = arguments.length === 3 - ? toUSVString(filename) + ? webidl.converters.USVString(filename) : undefined // 2. Let entry be the result of creating an entry with name, value, and @@ -238,15 +238,12 @@ Object.defineProperties(FormData.prototype, { */ function makeEntry (name, value, filename) { // 1. Set name to the result of converting name into a scalar value string. - // "To convert a string into a scalar value string, replace any surrogates - // with U+FFFD." - // see: https://nodejs.org/dist/latest-v20.x/docs/api/buffer.html#buftostringencoding-start-end - name = Buffer.from(name).toString('utf8') + // Note: This operation was done by the webidl converter USVString. // 2. If value is a string, then set value to the result of converting // value into a scalar value string. if (typeof value === 'string') { - value = Buffer.from(value).toString('utf8') + // Note: This operation was done by the webidl converter USVString. } else { // 3. Otherwise: