perf: slightly optimize Vec usage
This commit is contained in:
@@ -41,7 +41,7 @@ pub async fn get_block_states(
|
||||
lua: Lua,
|
||||
(block_names, filter_fn): (Vec<String>, Option<Function>),
|
||||
) -> Result<Vec<u16>> {
|
||||
let mut matched = Vec::new();
|
||||
let mut matched = Vec::with_capacity(16);
|
||||
for block_name in block_names {
|
||||
for block in
|
||||
(u32::MIN..u32::MAX).map_while(|possible_id| BlockState::try_from(possible_id).ok())
|
||||
|
@@ -109,11 +109,7 @@ fn id(_lua: &Lua, client: &Client) -> Result<i32> {
|
||||
}
|
||||
|
||||
fn tab_list(_lua: &Lua, client: &Client) -> Result<Vec<Player>> {
|
||||
let mut tab_list = Vec::new();
|
||||
for (_, player_info) in client.tab_list() {
|
||||
tab_list.push(Player::from(player_info));
|
||||
}
|
||||
Ok(tab_list)
|
||||
Ok(client.tab_list().into_values().map(Player::from).collect())
|
||||
}
|
||||
|
||||
fn username(_lua: &Lua, client: &Client) -> Result<String> {
|
||||
|
@@ -56,7 +56,7 @@ pub async fn find_all_entities(
|
||||
client: UserDataRef<Client>,
|
||||
(): (),
|
||||
) -> Result<Vec<Table>> {
|
||||
let mut matched = Vec::new();
|
||||
let mut matched = Vec::with_capacity(256);
|
||||
for (position, custom_name, kind, uuid, direction, id, owner_uuid, pose) in
|
||||
get_entities!(client)
|
||||
{
|
||||
|
@@ -13,7 +13,7 @@ pub struct Player {
|
||||
impl From<PlayerInfo> for Player {
|
||||
fn from(p: PlayerInfo) -> Self {
|
||||
Self {
|
||||
display_name: p.display_name.map(|n| n.to_string()),
|
||||
display_name: p.display_name.map(|text| text.to_string()),
|
||||
gamemode: p.gamemode.to_id(),
|
||||
latency: p.latency,
|
||||
name: p.profile.name,
|
||||
|
Reference in New Issue
Block a user