MCPcopy
hub / github.com/webpack/webpack / popCommonItems

Function popCommonItems

lib/util/compileBooleanMatcher.js:146–172  ·  view source on GitHub ↗
(itemsSet, getKey, condition)

Source from the content-addressed store, hash-verified

144 * @returns {ListOfCommonItems} list of common items
145 */
146const popCommonItems = (itemsSet, getKey, condition) => {
147 /** @type {Map<string, string[]>} */
148 const map = new Map();
149 for (const item of itemsSet) {
150 const key = getKey(item);
151 if (key) {
152 let list = map.get(key);
153 if (list === undefined) {
154 /** @type {string[]} */
155 list = [];
156 map.set(key, list);
157 }
158 list.push(item);
159 }
160 }
161 /** @type {ListOfCommonItems} */
162 const result = [];
163 for (const list of map.values()) {
164 if (condition(list)) {
165 for (const item of list) {
166 itemsSet.delete(item);
167 }
168 result.push(list);
169 }
170 }
171 return result;
172};
173
174/**
175 * Gets common prefix.

Callers 1

itemsToRegexpFunction · 0.85

Calls 5

getMethod · 0.45
setMethod · 0.45
pushMethod · 0.45
valuesMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected