Skip to content

Commit

Permalink
Fix inefficient buffer clippy warning on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
complexspaces committed Aug 25, 2024
1 parent 57bffe5 commit 22f2221
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ pub(crate) fn get() -> impl Iterator<Item = String> {
return Vec::new().into_iter();
}

let mut buffer = Vec::<u16>::new();
buffer.resize(buffer_length as usize, 0);
let mut buffer = Vec::<u16>::with_capacity(buffer_length as usize);

// Now that we have an appropriate buffer, we can query the names
let mut result = Vec::with_capacity(num_languages as usize);
Expand All @@ -37,6 +36,8 @@ pub(crate) fn get() -> impl Iterator<Item = String> {
} == TRUE;

if success {
// SAFETY: Windows wrote the required length worth of UTF-16 into our buffer, which initialized it.
unsafe { buffer.set_len(buffer_length as usize) };
// The buffer contains names split by null char (0), and ends with two null chars (00)
for part in buffer.split(|i| *i == 0).filter(|p| !p.is_empty()) {
if let Ok(locale) = String::from_utf16(part) {
Expand Down

0 comments on commit 22f2221

Please sign in to comment.