Skip to content

Commit

Permalink
[INTERNAL] Use Object.create(null) for dynamic maps
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Nov 8, 2022
1 parent 0d16ccc commit d811a1d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/lbt/resources/LibraryFileAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function createRawInfo(rawModule) {
}

export function getDependencyInfos( name, content ) {
const infos = {};
const infos = Object.create(null);
parser.parseString(content, (err, result) => {
if ( result &&
result.library &&
Expand Down
2 changes: 1 addition & 1 deletion lib/lbt/resources/ModuleInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ModuleInfo {
constructor(name) {
this._name = name;
this.subModules = [];
this._dependencies = {};
this._dependencies = Object.create(null);
this.dynamicDependencies = false;

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/processors/manifestCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ async function createManifest(
}

function collectThemes() {
const themes = {};
const themes = Object.create(null);

// find theme resources and determine theme names from their paths
libBundle.getResources(/(?:[^/]+\/)*themes\//).forEach((res) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/processors/nonAsciiEscaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import escapeUnicode from "escape-unicode";
const CHAR_CODE_OF_LAST_ASCII_CHARACTER = 127;

// use memoization for escapeUnicode function for performance
const memoizeEscapeUnicodeMap = {};
const memoizeEscapeUnicodeMap = Object.create(null);
const memoizeEscapeUnicode = function(sChar) {
if (memoizeEscapeUnicodeMap[sChar]) {
return memoizeEscapeUnicodeMap[sChar];
Expand Down
12 changes: 6 additions & 6 deletions lib/processors/versionInfoGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ function getTimestamp() {
const processManifest = async (manifestResource) => {
const manifestContent = await manifestResource.getString();
const manifestObject = JSON.parse(manifestContent);
const manifestInfo = {};
const manifestInfo = Object.create(null);

// sap.ui5/dependencies is used for the "manifestHints/libs"
if (manifestObject["sap.ui5"]) {
const manifestDependencies = manifestObject["sap.ui5"]["dependencies"];
if (manifestDependencies && manifestDependencies.libs) {
const libs = {};
const libs = Object.create(null);
for (const [libKey, libValue] of Object.entries(manifestDependencies.libs)) {
libs[libKey] = {};
libs[libKey] = Object.create(null);
if (libValue.lazy) {
libs[libKey].lazy = true;
}
Expand Down Expand Up @@ -230,7 +230,7 @@ class DependencyInfo {
* @returns {object} the object with sorted keys
*/
const sortObjectKeys = (obj) => {
const sortedObject = {};
const sortedObject = Object.create(null);
const keys = Object.keys(obj);
keys.sort();
keys.forEach((key) => {
Expand Down Expand Up @@ -433,7 +433,7 @@ export default async function({options}) {
let components;
artifactInfos.forEach((artifactInfo) => {
artifactInfo.embeds.forEach((embeddedArtifactInfo) => {
const componentObject = {};
const componentObject = Object.create(null);
const bundledComponents = artifactInfo.bundledComponents;
const componentName = embeddedArtifactInfo.componentName;
if (!bundledComponents.has(componentName)) {
Expand All @@ -446,7 +446,7 @@ export default async function({options}) {
componentObject.manifestHints = manifestHints;
}

components = components || {};
components = components || Object.create(null);
components[componentName] = componentObject;
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/bundlers/utils/createModuleNameMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {getNonDebugName} from "../../../lbt/utils/ModuleName.js";
* @returns {object} Module name mapping
*/
export default function({resources, taskUtil}) {
const moduleNameMapping = {};
const moduleNameMapping = Object.create(null);
for (let i = resources.length - 1; i >= 0; i--) {
const resource = resources[i];
if (taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.IsDebugVariant)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/generateCachebusterInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function({workspace, options}) {
const basePath = `/resources/${namespace}/`;
return workspace.byGlob(`/resources/${namespace}/**/*`)
.then(async (resources) => {
const cachebusterInfo = {};
const cachebusterInfo = Object.create(null);
const signer = getSigner(signatureType);

await Promise.all(resources.map(async (resource) => {
Expand Down

0 comments on commit d811a1d

Please sign in to comment.