зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1874696 - [devtools] Use a Set (instead of Array) for removed message IDs. r=devtools-reviewers,nchevobbe
As we are only doing inclusion test, and this dataset is often large, this will be signficantly faster. Differential Revision: https://phabricator.services.mozilla.com/D197771
This commit is contained in:
Родитель
29d8da4d9b
Коммит
7ef76d10d3
|
@ -453,15 +453,15 @@ function messages(
|
|||
});
|
||||
|
||||
case constants.PRIVATE_MESSAGES_CLEAR: {
|
||||
const removedIds = [];
|
||||
const removedIds = new Set();
|
||||
for (const [id, message] of mutableMessagesById) {
|
||||
if (message.private === true) {
|
||||
removedIds.push(id);
|
||||
removedIds.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
// If there's no private messages, there's no need to change the state.
|
||||
if (removedIds.length === 0) {
|
||||
if (removedIds.size === 0) {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -474,7 +474,7 @@ function messages(
|
|||
}
|
||||
|
||||
case constants.TARGET_MESSAGES_REMOVE: {
|
||||
const removedIds = [];
|
||||
const removedIds = new Set();
|
||||
for (const [id, message] of mutableMessagesById) {
|
||||
// Remove message from the target but not evaluations and their results, so
|
||||
// 1. we're consistent with the filtering behavior, i.e. we never hide those
|
||||
|
@ -486,7 +486,7 @@ function messages(
|
|||
message.type !== MESSAGE_TYPE.COMMAND &&
|
||||
message.type !== MESSAGE_TYPE.RESULT
|
||||
) {
|
||||
removedIds.push(id);
|
||||
removedIds.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -724,7 +724,7 @@ function messages(
|
|||
{
|
||||
...state,
|
||||
},
|
||||
[action.id]
|
||||
new Set([action.id])
|
||||
);
|
||||
|
||||
case constants.FILTER_TOGGLE:
|
||||
|
@ -853,7 +853,7 @@ function setVisibleMessages({
|
|||
* @param {Array} ignoredIds: An array of ids which can't be the new current group.
|
||||
* @returns {String|null} The new current group id, or null if there isn't one.
|
||||
*/
|
||||
function getNewCurrentGroup(currentGroup, groupsById, ignoredIds = []) {
|
||||
function getNewCurrentGroup(currentGroup, groupsById, ignoredIds = new Set()) {
|
||||
if (!currentGroup) {
|
||||
return null;
|
||||
}
|
||||
|
@ -864,7 +864,7 @@ function getNewCurrentGroup(currentGroup, groupsById, ignoredIds = []) {
|
|||
// If there's at least one parent, make the first one the new currentGroup.
|
||||
if (Array.isArray(parents) && parents.length) {
|
||||
// If the found group must be ignored, let's search for its parent.
|
||||
if (ignoredIds.includes(parents[0])) {
|
||||
if (ignoredIds.has(parents[0])) {
|
||||
return getNewCurrentGroup(parents[0], groupsById, ignoredIds);
|
||||
}
|
||||
|
||||
|
@ -913,7 +913,7 @@ function limitTopLevelMessageCount(newState, logLimit) {
|
|||
return newState;
|
||||
}
|
||||
|
||||
const removedMessagesId = [];
|
||||
const removedMessagesId = new Set();
|
||||
|
||||
let cleaningGroup = false;
|
||||
for (const id of newState.mutableMessagesOrder) {
|
||||
|
@ -940,7 +940,7 @@ function limitTopLevelMessageCount(newState, logLimit) {
|
|||
topLevelCount--;
|
||||
}
|
||||
|
||||
removedMessagesId.push(id);
|
||||
removedMessagesId.add(id);
|
||||
}
|
||||
|
||||
return removeMessagesFromState(newState, removedMessagesId);
|
||||
|
@ -951,11 +951,11 @@ function limitTopLevelMessageCount(newState, logLimit) {
|
|||
* Be aware that this function MUTATE the `state` argument.
|
||||
*
|
||||
* @param {MessageState} state
|
||||
* @param {Array} removedMessagesIds
|
||||
* @param {Set} removedMessagesIds
|
||||
* @returns {MessageState}
|
||||
*/
|
||||
function removeMessagesFromState(state, removedMessagesIds) {
|
||||
if (!Array.isArray(removedMessagesIds) || removedMessagesIds.length === 0) {
|
||||
if (removedMessagesIds.size === 0) {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -984,8 +984,15 @@ function removeMessagesFromState(state, removedMessagesIds) {
|
|||
state.frontsToRelease = state.frontsToRelease.concat(frontsToRelease);
|
||||
}
|
||||
|
||||
const isInRemovedId = id => removedMessagesIds.includes(id);
|
||||
const mapHasRemovedIdKey = map => removedMessagesIds.some(id => map.has(id));
|
||||
const isInRemovedId = id => removedMessagesIds.has(id);
|
||||
const mapHasRemovedIdKey = map => {
|
||||
for (const id of removedMessagesIds) {
|
||||
if (map.has(id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const objectHasRemovedIdKey = obj =>
|
||||
Object.keys(obj).findIndex(isInRemovedId) !== -1;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче