more efficient code

pull/225/head
Aevann 2024-03-07 19:57:46 +02:00
parent 8721b4b327
commit 5eb90d3466
2 changed files with 14 additions and 10 deletions

View File

@ -2,6 +2,8 @@ let groupSearchDictionaryState = "inactive";
let globalGroups = [];
const groupMAXXX = 50;
const groupsSearchDictionary = {
array: [],
@ -28,9 +30,11 @@ const groupsSearchDictionary = {
query = query.toLowerCase()
const result = new Set();
for (let i = 0; i < this.array.length; i++)
for (let i = 0; i < this.array.length; i++) {
if (result.size > groupMAXXX) break;
if (this.array[i].toLowerCase().includes(query))
result.add(this.array[i])
}
return result;
}
@ -85,18 +89,17 @@ function populate_inline_group_modal(results, textbox)
if (!results || results.size === 0)
{
inline_carot_modal.style.display = "none";
return -1;
return;
}
group_index = 0;
inline_carot_modal.scrollTop = 0;
inline_carot_modal.innerHTML = "";
const MAXXX = 50;
// Not sure why the results is a Set... but oh well
let i = 0;
for (let name of results)
{
if (i++ > MAXXX) return i;
i++;
let group_option = document.createElement("div");
group_option.className = "inline-modal-option group-option " + (i === 1 ? "selected" : "");
group_option.tabIndex = 0;
@ -118,5 +121,4 @@ function populate_inline_group_modal(results, textbox)
}
if (i === 0) inline_carot_modal.style.display = "none";
else inline_carot_modal.style.display = "initial";
return i;
}

View File

@ -2,6 +2,8 @@ let userSearchDictionaryState = "inactive";
let globalUsers = [];
const userMAXXX = 50;
const usersSearchDictionary = {
array: [],
@ -28,9 +30,11 @@ const usersSearchDictionary = {
query = query.toLowerCase()
const result = new Set();
for (let i = 0; i < this.array.length; i++)
for (let i = 0; i < this.array.length; i++) {
if (result.size > userMAXXX) break;
if (this.array[i].toLowerCase().includes(query))
result.add(this.array[i])
}
return result;
}
@ -85,18 +89,17 @@ function populate_inline_user_modal(results, textbox)
if (!results || results.size === 0)
{
inline_carot_modal.style.display = "none";
return -1;
return;
}
user_index = 0;
inline_carot_modal.scrollTop = 0;
inline_carot_modal.innerHTML = "";
const MAXXX = 50;
// Not sure why the results is a Set... but oh well
let i = 0;
for (let name of results)
{
if (i++ > MAXXX) return i;
i++;
let user_option = document.createElement("div");
user_option.className = "inline-modal-option user-option " + (i === 1 ? "selected" : "");
user_option.tabIndex = 0;
@ -124,5 +127,4 @@ function populate_inline_user_modal(results, textbox)
}
if (i === 0) inline_carot_modal.style.display = "none";
else inline_carot_modal.style.display = "initial";
return i;
}