int_dict: Remove filter_values method.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-02-03 00:35:14 -08:00
committed by Tim Abbott
parent 1cdab5ae61
commit 7cc16757aa
4 changed files with 21 additions and 35 deletions

View File

@@ -79,22 +79,6 @@ run_test('benchmark', () => {
});
*/
run_test('filter_values', () => {
const d = new IntDict();
d.set(1, "fred");
d.set(2, "foo");
d.set(3, "bar");
d.set(4, "baz");
d.set(4, "fay");
const pred = (v) => {
return v.startsWith('f');
};
assert.deepEqual(d.filter_values(pred).sort(), ['fay', 'foo', 'fred']);
});
run_test('undefined_keys', () => {
blueslip.clear_test_data();
blueslip.set_test_data('error', 'Tried to call a IntDict method with an undefined key.');

View File

@@ -57,15 +57,23 @@ exports.update = function bot_data__update(bot_id, bot_update) {
};
exports.get_all_bots_for_current_user = function bots_data__get_editable() {
return bots.filter_values(function (bot) {
return people.is_current_user(bot.owner);
});
const ret = [];
for (const bot of bots.values()) {
if (people.is_current_user(bot.owner)) {
ret.push(bot);
}
}
return ret;
};
exports.get_editable = function bots_data__get_editable() {
return bots.filter_values(function (bot) {
return bot.is_active && people.is_current_user(bot.owner);
});
const ret = [];
for (const bot of bots.values()) {
if (bot.is_active && people.is_current_user(bot.owner)) {
ret.push(bot);
}
}
return ret;
};
exports.get = function bot_data__get(bot_id) {

View File

@@ -54,18 +54,6 @@ export class IntDict<V> {
return this._map.entries();
}
filter_values(pred: (item: V) => boolean): V[] {
const results: V[] = [];
this._map.forEach(function (v: V) {
if (pred(v)) {
results.push(v);
}
});
return results;
}
get size(): number {
return this._map.size;
}

View File

@@ -681,7 +681,13 @@ exports.is_active_user_for_popover = function (user_id) {
};
exports.filter_all_persons = function (pred) {
return people_by_user_id_dict.filter_values(pred);
const ret = [];
for (const person of people_by_user_id_dict.values()) {
if (pred(person)) {
ret.push(person);
}
}
return ret;
};
exports.get_realm_persons = function () {