Skip to content

Commit

Permalink
remove dead code (#1943)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Aug 2, 2022
1 parent d40a518 commit 104ecd6
Showing 1 changed file with 0 additions and 30 deletions.
30 changes: 0 additions & 30 deletions crates/libs/windows/src/core/heap.rs
Expand Up @@ -37,33 +37,3 @@ pub unsafe fn heap_free(ptr: *mut core::ffi::c_void) {
HeapFree(heap, HEAP_NONE, ptr);
}
}

/// Copy len elements of an iterator of type `T` into a freshly allocated buffer.
///
/// Returns a pointer to the beginning of the buffer. This pointer must be freed when done using `heap_free`.
///
/// # Panics
///
/// This function panics if the heap allocation fails, the alignment requirements of 'T' surpass
/// 8 (HeapAlloc's alignment).
pub fn alloc_from_iter<I, T>(iter: I, len: usize) -> *const T
where
I: Iterator<Item = T>,
T: Copy,
{
// alignment of memory returned by HeapAlloc is at least 8
// Source: https://docs.microsoft.com/en-us/windows/win32/api/heapapi/nf-heapapi-heapalloc
// Ensure that T has sufficient alignment requirements
assert!(std::mem::align_of::<T>() <= 8, "T alignment surpasses HeapAlloc alignment");

let ptr = heap_alloc(len * std::mem::size_of::<T>()).expect("could not allocate string") as *mut T;

for (offset, c) in iter.take(len).enumerate() {
// SAFETY: ptr points to an allocation object of size `len`, indices accessed are always lower than `len`
unsafe {
ptr.add(offset).write(c);
}
}

ptr
}

0 comments on commit 104ecd6

Please sign in to comment.