From dfa25b96f7367d7dcb3dbb07d6b33664e4b82b9b Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 18 Dec 2020 10:26:07 +0100 Subject: [PATCH] Rename SharedArray to SharedVector --- CHANGELOG.md | 1 + api/sixtyfps-cpp/CMakeLists.txt | 2 +- api/sixtyfps-cpp/include/sixtyfps.h | 2 +- api/sixtyfps-cpp/include/sixtyfps_pathdata.h | 8 +- ..._sharedarray.h => sixtyfps_sharedvector.h} | 48 ++++---- api/sixtyfps-rs/lib.rs | 4 +- sixtyfps_compiler/generator/rust.rs | 6 +- sixtyfps_runtime/corelib/graphics.rs | 20 +-- sixtyfps_runtime/corelib/items.rs | 2 +- sixtyfps_runtime/corelib/lib.rs | 6 +- sixtyfps_runtime/corelib/model.rs | 2 +- .../{sharedarray.rs => sharedvector.rs} | 116 +++++++++--------- sixtyfps_runtime/interpreter/eval.rs | 8 +- .../rendering_backends/qt/widgets.rs | 6 +- tests/driver_lib/cbindgen.rs | 12 +- 15 files changed, 122 insertions(+), 121 deletions(-) rename api/sixtyfps-cpp/include/{sixtyfps_sharedarray.h => sixtyfps_sharedvector.h} (71%) rename sixtyfps_runtime/corelib/{sharedarray.rs => sharedvector.rs} (80%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ca8a6de8..fefbb3034 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. ### Changed - Renamed "signal" to "callback" + - Renamed "SharedArray" to "SharedVector" in the C++/Rust API ## [0.0.4] - 2020-12-04 diff --git a/api/sixtyfps-cpp/CMakeLists.txt b/api/sixtyfps-cpp/CMakeLists.txt index 80a25df16..ab351a7f6 100644 --- a/api/sixtyfps-cpp/CMakeLists.txt +++ b/api/sixtyfps-cpp/CMakeLists.txt @@ -35,7 +35,7 @@ endforeach() set(generated_headers ${CMAKE_CURRENT_BINARY_DIR}/generated_include/sixtyfps_internal.h ${CMAKE_CURRENT_BINARY_DIR}/generated_include/sixtyfps_string_internal.h - ${CMAKE_CURRENT_BINARY_DIR}/generated_include/sixtyfps_sharedarray_internal.h + ${CMAKE_CURRENT_BINARY_DIR}/generated_include/sixtyfps_sharedvector_internal.h ${CMAKE_CURRENT_BINARY_DIR}/generated_include/sixtyfps_properties_internal.h ${CMAKE_CURRENT_BINARY_DIR}/generated_include/sixtyfps_resource_internal.h ${CMAKE_CURRENT_BINARY_DIR}/generated_include/sixtyfps_color_internal.h diff --git a/api/sixtyfps-cpp/include/sixtyfps.h b/api/sixtyfps-cpp/include/sixtyfps.h index fe824502c..972af772f 100644 --- a/api/sixtyfps-cpp/include/sixtyfps.h +++ b/api/sixtyfps-cpp/include/sixtyfps.h @@ -409,7 +409,7 @@ struct IntModel : Model int row_data(int value) const override { return value; } }; -/// A Model backed by a SharedArray +/// A Model backed by a SharedVector template class VectorModel : public Model { diff --git a/api/sixtyfps-cpp/include/sixtyfps_pathdata.h b/api/sixtyfps-cpp/include/sixtyfps_pathdata.h index d618be772..abf994a77 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_pathdata.h +++ b/api/sixtyfps-cpp/include/sixtyfps_pathdata.h @@ -56,10 +56,10 @@ public: private: - static SharedArray elements_from_array(const PathElement *firstElement, + static SharedVector elements_from_array(const PathElement *firstElement, size_t count) { - SharedArray tmp; + SharedVector tmp; sixtyfps_new_path_elements(&tmp, firstElement, count); return tmp; } @@ -69,8 +69,8 @@ private: const Point *firstCoordinate, size_t coordinate_count) { - SharedArray events; - SharedArray coordinates; + SharedVector events; + SharedVector coordinates; sixtyfps_new_path_events(&events, &coordinates, firstEvent, event_count, firstCoordinate, coordinate_count); return Data::Events(events, coordinates); diff --git a/api/sixtyfps-cpp/include/sixtyfps_sharedarray.h b/api/sixtyfps-cpp/include/sixtyfps_sharedvector.h similarity index 71% rename from api/sixtyfps-cpp/include/sixtyfps_sharedarray.h rename to api/sixtyfps-cpp/include/sixtyfps_sharedvector.h index bb99034c9..7d85eee01 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_sharedarray.h +++ b/api/sixtyfps-cpp/include/sixtyfps_sharedvector.h @@ -8,32 +8,32 @@ Please contact info@sixtyfps.io for more information. LICENSE END */ #pragma once -#include "sixtyfps_sharedarray_internal.h" +#include "sixtyfps_sharedvector_internal.h" #include #include namespace sixtyfps { template -struct SharedArray +struct SharedVector { - SharedArray() - : inner(const_cast(reinterpret_cast( - cbindgen_private::sixtyfps_shared_array_empty()))) + SharedVector() + : inner(const_cast(reinterpret_cast( + cbindgen_private::sixtyfps_shared_vector_empty()))) { } - SharedArray(const SharedArray &other) + SharedVector(const SharedVector &other) : inner(other.inner) { if (inner->refcount > 0) { ++inner->refcount; } } - ~SharedArray() + ~SharedVector() { drop(); } - SharedArray &operator=(const SharedArray &other) + SharedVector &operator=(const SharedVector &other) { if (other.inner == inner) { return *this; } drop(); @@ -43,7 +43,7 @@ struct SharedArray } return *this; } - SharedArray &operator=(SharedArray &&other) + SharedVector &operator=(SharedVector &&other) { std::swap(inner, other.inner); return *this; @@ -96,12 +96,12 @@ struct SharedArray inner->size++; } - friend bool operator==(const SharedArray &a, const SharedArray &b) { + friend bool operator==(const SharedVector &a, const SharedVector &b) { if (a.size() != a.size()) return false; return std::equal(a.cbegin(), a.cend(), b.cbegin()); } - friend bool operator!=(const SharedArray &a, const SharedArray &b) { + friend bool operator!=(const SharedVector &a, const SharedVector &b) { return !(a == b); } @@ -111,7 +111,7 @@ private: if (inner->refcount == 1 && expected_capacity <= inner->capacity) { return; } - auto new_array = SharedArray::with_capacity(expected_capacity); + auto new_array = SharedVector::with_capacity(expected_capacity); auto old_data = reinterpret_cast(inner + 1); auto new_data = reinterpret_cast(new_array.inner + 1); for (std::size_t i = 0; i < inner->size; ++i) { @@ -127,30 +127,30 @@ private: for (auto it = b; it < e; ++it) { it->~T(); } - cbindgen_private::sixtyfps_shared_array_free( + cbindgen_private::sixtyfps_shared_vector_free( reinterpret_cast(inner), - sizeof(SharedArrayHeader) + inner->capacity * sizeof(T), - alignof(SharedArrayHeader)); + sizeof(SharedVectorHeader) + inner->capacity * sizeof(T), + alignof(SharedVectorHeader)); } } - static SharedArray with_capacity(std::size_t capacity) { - auto mem = cbindgen_private::sixtyfps_shared_array_allocate( - sizeof(SharedArrayHeader) + capacity * sizeof(T), - alignof(SharedArrayHeader)); - return SharedArray(new (mem) SharedArrayHeader{ {1}, 0, capacity }); + static SharedVector with_capacity(std::size_t capacity) { + auto mem = cbindgen_private::sixtyfps_shared_vector_allocate( + sizeof(SharedVectorHeader) + capacity * sizeof(T), + alignof(SharedVectorHeader)); + return SharedVector(new (mem) SharedVectorHeader{ {1}, 0, capacity }); } #if !defined(DOXYGEN) // Unfortunately, this cannot be generated by cbindgen because std::atomic is not understood - struct SharedArrayHeader { + struct SharedVectorHeader { std::atomic refcount; std::size_t size; std::size_t capacity; }; - static_assert(alignof(T) <= alignof(SharedArrayHeader), "Not yet supported because we would need to add padding"); - SharedArrayHeader *inner; - explicit SharedArray(SharedArrayHeader *inner) : inner(inner) {} + static_assert(alignof(T) <= alignof(SharedVectorHeader), "Not yet supported because we would need to add padding"); + SharedVectorHeader *inner; + explicit SharedVector(SharedVectorHeader *inner) : inner(inner) {} #endif }; diff --git a/api/sixtyfps-rs/lib.rs b/api/sixtyfps-rs/lib.rs index cd9945210..1ccd8de01 100644 --- a/api/sixtyfps-rs/lib.rs +++ b/api/sixtyfps-rs/lib.rs @@ -157,7 +157,7 @@ pub use sixtyfps_corelib::font::register_application_font_from_memory; pub use sixtyfps_corelib::model::{ Model, ModelHandle, ModelNotify, ModelPeer, StandardListViewItem, VecModel, }; -pub use sixtyfps_corelib::sharedarray::SharedArray; +pub use sixtyfps_corelib::sharedvector::SharedVector; pub use sixtyfps_corelib::string::SharedString; pub use sixtyfps_corelib::timers::{Timer, TimerMode}; pub use sixtyfps_corelib::{Color, RgbaColor}; @@ -200,7 +200,7 @@ pub mod re_exports { pub use sixtyfps_corelib::Color; pub use sixtyfps_corelib::ComponentVTable_static; pub use sixtyfps_corelib::Resource; - pub use sixtyfps_corelib::SharedArray; + pub use sixtyfps_corelib::SharedVector; pub use sixtyfps_corelib::SharedString; pub use sixtyfps_rendering_backend_default::native_widgets::*; pub use vtable::{self, *}; diff --git a/sixtyfps_compiler/generator/rust.rs b/sixtyfps_compiler/generator/rust.rs index d669d32d9..22e45b77d 100644 --- a/sixtyfps_compiler/generator/rust.rs +++ b/sixtyfps_compiler/generator/rust.rs @@ -1930,8 +1930,8 @@ fn compile_path_events(events: &crate::expression_tree::PathEvents) -> TokenStre }) .collect(); - quote!(sixtyfps::re_exports::SharedArray::::from_slice(&[#(#converted_events),*]), - sixtyfps::re_exports::SharedArray::::from_slice(&[#(#coordinates),*])) + quote!(sixtyfps::re_exports::SharedVector::::from_slice(&[#(#converted_events),*]), + sixtyfps::re_exports::SharedVector::::from_slice(&[#(#coordinates),*])) } fn compile_path(path: &Path, component: &Rc) -> TokenStream { @@ -1973,7 +1973,7 @@ fn compile_path(path: &Path, component: &Rc) -> TokenStream { .collect(); quote!(sixtyfps::re_exports::PathData::Elements( - sixtyfps::re_exports::SharedArray::::from_slice(&[#(#converted_elements),*]) + sixtyfps::re_exports::SharedVector::::from_slice(&[#(#converted_elements),*]) )) } Path::Events(events) => { diff --git a/sixtyfps_runtime/corelib/graphics.rs b/sixtyfps_runtime/corelib/graphics.rs index 9ac5289fb..cb0d77539 100644 --- a/sixtyfps_runtime/corelib/graphics.rs +++ b/sixtyfps_runtime/corelib/graphics.rs @@ -236,7 +236,7 @@ pub enum Resource { EmbeddedData(super::slice::Slice<'static, u8>), /// Raw ARGB #[allow(missing_docs)] - EmbeddedRgbaImage { width: u32, height: u32, data: super::sharedarray::SharedArray }, + EmbeddedRgbaImage { width: u32, height: u32, data: super::sharedvector::SharedVector }, } impl Default for Resource { @@ -1141,7 +1141,7 @@ pub struct PathDataIterator<'a> { enum LyonPathIteratorVariant<'a> { FromPath(lyon::path::Path), - FromEvents(&'a crate::SharedArray, &'a crate::SharedArray), + FromEvents(&'a crate::SharedVector, &'a crate::SharedVector), } impl<'a> PathDataIterator<'a> { @@ -1193,10 +1193,10 @@ pub enum PathData { /// None is the variant when the path is empty. None, /// The Elements variant is used to make a Path from shared arrays of elements. - Elements(crate::SharedArray), + Elements(crate::SharedVector), /// The Events variant describes the path as a series of low-level events and /// associated coordinates. - Events(crate::SharedArray, crate::SharedArray), + Events(crate::SharedVector, crate::SharedVector), } impl Default for PathData { @@ -1322,8 +1322,8 @@ pub(crate) mod ffi { first_element: *const PathElement, count: usize, ) { - let arr = crate::SharedArray::from(std::slice::from_raw_parts(first_element, count)); - core::ptr::write(out as *mut crate::SharedArray, arr.clone()); + let arr = crate::SharedVector::from(std::slice::from_raw_parts(first_element, count)); + core::ptr::write(out as *mut crate::SharedVector, arr.clone()); } #[no_mangle] @@ -1336,13 +1336,13 @@ pub(crate) mod ffi { first_coordinate: *const Point, coordinate_count: usize, ) { - let events = crate::SharedArray::from(std::slice::from_raw_parts(first_event, event_count)); - core::ptr::write(out_events as *mut crate::SharedArray, events.clone()); - let coordinates = crate::SharedArray::from(std::slice::from_raw_parts( + let events = crate::SharedVector::from(std::slice::from_raw_parts(first_event, event_count)); + core::ptr::write(out_events as *mut crate::SharedVector, events.clone()); + let coordinates = crate::SharedVector::from(std::slice::from_raw_parts( first_coordinate, coordinate_count, )); - core::ptr::write(out_coordinates as *mut crate::SharedArray, coordinates.clone()); + core::ptr::write(out_coordinates as *mut crate::SharedVector, coordinates.clone()); } } diff --git a/sixtyfps_runtime/corelib/items.rs b/sixtyfps_runtime/corelib/items.rs index ba52893e6..926008d3a 100644 --- a/sixtyfps_runtime/corelib/items.rs +++ b/sixtyfps_runtime/corelib/items.rs @@ -650,7 +650,7 @@ ItemVTable_static! { pub static FlickableVTable for Flickable } -pub use crate::{graphics::RenderingVariables, SharedArray}; +pub use crate::{graphics::RenderingVariables, SharedVector}; #[repr(C)] /// Wraps the internal datastructure for the Flickable diff --git a/sixtyfps_runtime/corelib/lib.rs b/sixtyfps_runtime/corelib/lib.rs index d237fc8dc..f2bdea0ce 100644 --- a/sixtyfps_runtime/corelib/lib.rs +++ b/sixtyfps_runtime/corelib/lib.rs @@ -34,7 +34,7 @@ pub mod component; pub mod items; pub mod model; pub mod properties; -pub mod sharedarray; +pub mod sharedvector; pub mod callbacks; pub mod string; @@ -42,7 +42,7 @@ pub mod string; pub use string::SharedString; #[doc(inline)] -pub use sharedarray::SharedArray; +pub use sharedvector::SharedVector; #[doc(inline)] pub use graphics::Resource; @@ -77,7 +77,7 @@ pub mod timers; pub fn use_modules() -> usize { tests::sixtyfps_mock_elapsed_time as usize + callbacks::ffi::sixtyfps_callback_init as usize - + sharedarray::ffi::sixtyfps_shared_array_empty as usize + + sharedvector::ffi::sixtyfps_shared_vector_empty as usize + layout::solve_grid_layout as usize + item_tree::ffi::sixtyfps_visit_item_tree as usize + graphics::ffi::sixtyfps_new_path_elements as usize diff --git a/sixtyfps_runtime/corelib/model.rs b/sixtyfps_runtime/corelib/model.rs index 3a51ffe65..b60ea0c52 100644 --- a/sixtyfps_runtime/corelib/model.rs +++ b/sixtyfps_runtime/corelib/model.rs @@ -113,7 +113,7 @@ impl<'a, T> Iterator for ModelIterator<'a, T> { impl<'a, T> ExactSizeIterator for ModelIterator<'a, T> {} -/// A model backed by a SharedArray +/// A model backed by a SharedVector #[derive(Default)] pub struct VecModel { array: RefCell>, diff --git a/sixtyfps_runtime/corelib/sharedarray.rs b/sixtyfps_runtime/corelib/sharedvector.rs similarity index 80% rename from sixtyfps_runtime/corelib/sharedarray.rs rename to sixtyfps_runtime/corelib/sharedvector.rs index 348a49641..a7f2c922b 100644 --- a/sixtyfps_runtime/corelib/sharedarray.rs +++ b/sixtyfps_runtime/corelib/sharedvector.rs @@ -7,7 +7,7 @@ This file is also available under commercial licensing terms. Please contact info@sixtyfps.io for more information. LICENSE END */ -//! module for the SharedArray and related things +//! module for the SharedVector and related things #![allow(unsafe_code)] #![warn(missing_docs)] use core::fmt::Debug; @@ -18,26 +18,26 @@ use core::sync::atomic; use std::{alloc, iter::FromIterator}; #[repr(C)] -struct SharedArrayHeader { +struct SharedVectorHeader { refcount: atomic::AtomicIsize, size: usize, capacity: usize, } #[repr(C)] -struct SharedArrayInner { - header: SharedArrayHeader, +struct SharedVectorInner { + header: SharedVectorHeader, data: MaybeUninit, } fn compute_inner_layout(capacity: usize) -> alloc::Layout { - alloc::Layout::new::() + alloc::Layout::new::() .extend(alloc::Layout::array::(capacity).unwrap()) .unwrap() .0 } -unsafe fn drop_inner(inner: NonNull>) { +unsafe fn drop_inner(inner: NonNull>) { debug_assert_eq!(inner.as_ref().header.refcount.load(core::sync::atomic::Ordering::Relaxed), 0); let data_ptr = inner.as_ref().data.as_ptr(); for x in 0..inner.as_ref().header.size { @@ -49,14 +49,14 @@ unsafe fn drop_inner(inner: NonNull>) { ) } -/// Allocate the memory for the SharedArray with the given capacity. Return the inner with size and refcount set to 1 -fn alloc_with_capacity(capacity: usize) -> NonNull> { +/// Allocate the memory for the SharedVector with the given capacity. Return the inner with size and refcount set to 1 +fn alloc_with_capacity(capacity: usize) -> NonNull> { let ptr = unsafe { alloc::alloc(compute_inner_layout::(capacity)) }; assert!(!ptr.is_null(), "allocation of {:?} bytes failled", capacity); unsafe { core::ptr::write( - ptr as *mut SharedArrayHeader, - SharedArrayHeader { refcount: 1.into(), size: 0, capacity }, + ptr as *mut SharedVectorHeader, + SharedVectorHeader { refcount: 1.into(), size: 0, capacity }, ); } NonNull::new(ptr).unwrap().cast() @@ -80,12 +80,12 @@ fn capacity_for_grow(current_cap: usize, required_cap: usize, elem_size: usize) } #[repr(C)] -/// SharedArray holds a reference-counted read-only copy of `[T]`. -pub struct SharedArray { - inner: NonNull>, +/// SharedVector holds a reference-counted read-only copy of `[T]`. +pub struct SharedVector { + inner: NonNull>, } -impl Drop for SharedArray { +impl Drop for SharedVector { fn drop(&mut self) { unsafe { if self.inner.as_ref().header.refcount.load(atomic::Ordering::Relaxed) < 0 { @@ -98,18 +98,18 @@ impl Drop for SharedArray { } } -impl Clone for SharedArray { +impl Clone for SharedVector { fn clone(&self) -> Self { unsafe { if self.inner.as_ref().header.refcount.load(atomic::Ordering::Relaxed) > 0 { self.inner.as_ref().header.refcount.fetch_add(1, atomic::Ordering::SeqCst); } - return SharedArray { inner: self.inner }; + return SharedVector { inner: self.inner }; } } } -impl SharedArray { +impl SharedVector { /// Create a new empty array with a pre-allocated capacity in number of items pub fn with_capacity(capacity: usize) -> Self { Self { inner: alloc_with_capacity(capacity) } @@ -135,9 +135,9 @@ impl SharedArray { } } -impl SharedArray { - /// Create a SharedArray from a slice - pub fn from_slice(slice: &[T]) -> SharedArray { +impl SharedVector { + /// Create a SharedVector from a slice + pub fn from_slice(slice: &[T]) -> SharedVector { Self::from(slice) } @@ -149,7 +149,7 @@ impl SharedArray { if !is_shared && new_capacity <= self.capacity() { return; } - let mut new_array = SharedArray::with_capacity(new_capacity); + let mut new_array = SharedVector::with_capacity(new_capacity); core::mem::swap(&mut self.inner, &mut new_array.inner); let mut size = 0; let mut iter = new_array.into_iter(); @@ -189,12 +189,12 @@ impl SharedArray { /// If the array was bigger, extra elements will be discared /// /// ``` - /// use sixtyfps_corelib::SharedArray; - /// let mut shared_array = SharedArray::::from_slice(&[1, 2, 3]); - /// shared_array.resize(5, 8); - /// assert_eq!(shared_array.as_slice(), &[1, 2, 3, 8, 8]); - /// shared_array.resize(2, 0); - /// assert_eq!(shared_array.as_slice(), &[1, 2]); + /// use sixtyfps_corelib::SharedVector; + /// let mut shared_vector = SharedVector::::from_slice(&[1, 2, 3]); + /// shared_vector.resize(5, 8); + /// assert_eq!(shared_vector.as_slice(), &[1, 2, 3, 8, 8]); + /// shared_vector.resize(2, 0); + /// assert_eq!(shared_vector.as_slice(), &[1, 2]); /// ``` pub fn resize(&mut self, new_len: usize, value: T) { if self.len() == new_len { @@ -224,7 +224,7 @@ impl SharedArray { } } -impl Deref for SharedArray { +impl Deref for SharedVector { type Target = [T]; fn deref(&self) -> &Self::Target { self.as_slice() @@ -232,13 +232,13 @@ impl Deref for SharedArray { } /* FIXME: is this a good idea to implement DerefMut knowing what it might detach? -impl DerefMut for SharedArray { +impl DerefMut for SharedVector { fn deref_mut(&mut self) -> &mut Self::Target { self.as_slice_mut() } }*/ -impl From<&[T]> for SharedArray { +impl From<&[T]> for SharedVector { fn from(slice: &[T]) -> Self { let capacity = slice.len(); let mut result = Self::with_capacity(capacity); @@ -258,7 +258,7 @@ impl From<&[T]> for SharedArray { macro_rules! from_array { ($($n:literal)*) => { $( // FIXME: remove the Clone bound - impl From<[T; $n]> for SharedArray { + impl From<[T; $n]> for SharedVector { fn from(array: [T; $n]) -> Self { array.iter().cloned().collect() } @@ -268,7 +268,7 @@ macro_rules! from_array { from_array! {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31} -impl FromIterator for SharedArray { +impl FromIterator for SharedVector { fn from_iter>(iter: I) -> Self { let mut iter = iter.into_iter(); let mut capacity = iter.size_hint().0; @@ -314,29 +314,29 @@ impl FromIterator for SharedArray { } } -static SHARED_NULL: SharedArrayHeader = - SharedArrayHeader { refcount: std::sync::atomic::AtomicIsize::new(-1), size: 0, capacity: 0 }; +static SHARED_NULL: SharedVectorHeader = + SharedVectorHeader { refcount: std::sync::atomic::AtomicIsize::new(-1), size: 0, capacity: 0 }; -impl Default for SharedArray { +impl Default for SharedVector { fn default() -> Self { - SharedArray { inner: NonNull::from(&SHARED_NULL).cast() } + SharedVector { inner: NonNull::from(&SHARED_NULL).cast() } } } -impl Debug for SharedArray { +impl Debug for SharedVector { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.as_slice().fmt(f) } } -impl AsRef<[T]> for SharedArray { +impl AsRef<[T]> for SharedVector { #[inline] fn as_ref(&self) -> &[T] { self.as_slice() } } -impl PartialEq for SharedArray +impl PartialEq for SharedVector where U: ?Sized + AsRef<[T]>, T: PartialEq, @@ -346,9 +346,9 @@ where } } -impl Eq for SharedArray {} +impl Eq for SharedVector {} -impl IntoIterator for SharedArray { +impl IntoIterator for SharedVector { type Item = T; type IntoIter = IntoIter; fn into_iter(self) -> Self::IntoIter { @@ -366,15 +366,15 @@ impl IntoIterator for SharedArray { } enum IntoIterInner { - Shared(SharedArray, usize), + Shared(SharedVector, usize), // Elements up to the usize member are already moved out - UnShared(NonNull>, usize), + UnShared(NonNull>, usize), } impl Drop for IntoIterInner { fn drop(&mut self) { match self { - IntoIterInner::Shared(..) => { /* drop of SharedArray takes care of it */ } + IntoIterInner::Shared(..) => { /* drop of SharedVector takes care of it */ } IntoIterInner::UnShared(inner, begin) => unsafe { debug_assert_eq!(inner.as_ref().header.refcount.load(atomic::Ordering::Relaxed), 0); let data_ptr = inner.as_ref().data.as_ptr(); @@ -390,9 +390,9 @@ impl Drop for IntoIterInner { } } -/// An iterator that moves out of a SharedArray. +/// An iterator that moves out of a SharedVector. /// -/// This `struct` is created by the `into_iter` method on [`SharedArray`] (provided +/// This `struct` is created by the `into_iter` method on [`SharedVector`] (provided /// by the [`IntoIterator`] trait). pub struct IntoIter(IntoIterInner); @@ -421,22 +421,22 @@ impl Iterator for IntoIter { #[test] fn simple_test() { - let x: SharedArray = SharedArray::from([1, 2, 3]); - let y: SharedArray = SharedArray::from([3, 2, 1]); + let x: SharedVector = SharedVector::from([1, 2, 3]); + let y: SharedVector = SharedVector::from([3, 2, 1]); assert_eq!(x, x.clone()); assert_ne!(x, y); let z: [i32; 3] = [1, 2, 3]; assert_eq!(z, x.as_slice()); let vec: Vec = vec![1, 2, 3]; assert_eq!(x, vec); - let def: SharedArray = Default::default(); - assert_eq!(def, SharedArray::::default()); + let def: SharedVector = Default::default(); + assert_eq!(def, SharedVector::::default()); assert_ne!(def, x); } #[test] fn push_test() { - let mut x: SharedArray = SharedArray::from([1, 2, 3]); + let mut x: SharedVector = SharedVector::from([1, 2, 3]); let y = x.clone(); x.push(4); x.push(5); @@ -448,27 +448,27 @@ fn push_test() { #[test] #[should_panic] fn invalid_capacity_test() { - let _: SharedArray = SharedArray::with_capacity(usize::MAX / 2 - 1000); + let _: SharedVector = SharedVector::with_capacity(usize::MAX / 2 - 1000); } pub(crate) mod ffi { use super::*; #[no_mangle] - /// This function is used for the low-level C++ interface to allocate the backing vector of a SharedArray. - pub unsafe extern "C" fn sixtyfps_shared_array_allocate(size: usize, align: usize) -> *mut u8 { + /// This function is used for the low-level C++ interface to allocate the backing vector of a SharedVector. + pub unsafe extern "C" fn sixtyfps_shared_vector_allocate(size: usize, align: usize) -> *mut u8 { std::alloc::alloc(std::alloc::Layout::from_size_align(size, align).unwrap()) } #[no_mangle] - /// This function is used for the low-level C++ interface to deallocate the backing vector of a SharedArray - pub unsafe extern "C" fn sixtyfps_shared_array_free(ptr: *mut u8, size: usize, align: usize) { + /// This function is used for the low-level C++ interface to deallocate the backing vector of a SharedVector + pub unsafe extern "C" fn sixtyfps_shared_vector_free(ptr: *mut u8, size: usize, align: usize) { std::alloc::dealloc(ptr, std::alloc::Layout::from_size_align(size, align).unwrap()) } #[no_mangle] - /// This function is used for the low-level C++ interface to initialize the empty SharedArray. - pub unsafe extern "C" fn sixtyfps_shared_array_empty() -> *const u8 { + /// This function is used for the low-level C++ interface to initialize the empty SharedVector. + pub unsafe extern "C" fn sixtyfps_shared_vector_empty() -> *const u8 { &SHARED_NULL as *const _ as *const u8 } } diff --git a/sixtyfps_runtime/interpreter/eval.rs b/sixtyfps_runtime/interpreter/eval.rs index 385d98513..611b08b6a 100644 --- a/sixtyfps_runtime/interpreter/eval.rs +++ b/sixtyfps_runtime/interpreter/eval.rs @@ -21,7 +21,7 @@ use sixtyfps_corelib as corelib; use sixtyfps_corelib::rtti::AnimatedBindingKind; use sixtyfps_corelib::{ graphics::PathElement, items::ItemRef, items::PropertyAnimation, Color, PathData, Resource, - SharedArray, SharedString, Callback, + SharedVector, SharedString, Callback, }; use std::collections::HashMap; use std::rc::Rc; @@ -876,14 +876,14 @@ fn convert_from_lyon_path<'a>( .collect::>(); PathData::Events( - SharedArray::from(events.as_slice()), - SharedArray::from_iter(coordinates.into_iter().cloned()), + SharedVector::from(events.as_slice()), + SharedVector::from_iter(coordinates.into_iter().cloned()), ) } pub fn convert_path(path: &ExprPath, local_context: &mut EvalLocalContext) -> PathData { match path { - ExprPath::Elements(elements) => PathData::Elements(SharedArray::::from_iter( + ExprPath::Elements(elements) => PathData::Elements(SharedVector::::from_iter( elements.iter().map(|element| convert_path_element(element, local_context)), )), ExprPath::Events(events) => convert_from_lyon_path(events.iter()), diff --git a/sixtyfps_runtime/rendering_backends/qt/widgets.rs b/sixtyfps_runtime/rendering_backends/qt/widgets.rs index 46bc966a7..74e2f4d31 100644 --- a/sixtyfps_runtime/rendering_backends/qt/widgets.rs +++ b/sixtyfps_runtime/rendering_backends/qt/widgets.rs @@ -36,7 +36,7 @@ use sixtyfps_corelib::item_rendering::CachedRenderingData; use sixtyfps_corelib::items::{Item, ItemConsts, ItemRc, ItemVTable}; use sixtyfps_corelib::layout::LayoutInfo; use sixtyfps_corelib::rtti::*; -use sixtyfps_corelib::{ItemVTable_static, Property, SharedArray, SharedString, Callback}; +use sixtyfps_corelib::{ItemVTable_static, Property, SharedVector, SharedString, Callback}; use sixtyfps_corelib_macros::*; use std::rc::Rc; @@ -58,12 +58,12 @@ macro_rules! get_size { struct QImageWrapArray { /// The image reference the array, so the array must outlive the image without being detached or accessed img: qttypes::QImage, - array: SharedArray, + array: SharedVector, } impl QImageWrapArray { pub fn new(size: qttypes::QSize, dpr: f32) -> Self { - let mut array = SharedArray::default(); + let mut array = SharedVector::default(); array.resize((size.width * size.height) as usize, 0u32); let array_ptr = array.as_slice_mut().as_mut_ptr(); let img = cpp!(unsafe [size as "QSize", array_ptr as "uchar*", dpr as "float"] -> qttypes::QImage as "QImage" { diff --git a/tests/driver_lib/cbindgen.rs b/tests/driver_lib/cbindgen.rs index 2f0f23a2b..6242251cd 100644 --- a/tests/driver_lib/cbindgen.rs +++ b/tests/driver_lib/cbindgen.rs @@ -68,7 +68,7 @@ fn gen_corelib(include_dir: &Path) -> anyhow::Result<()> { config.export.exclude = [ "SharedString", - "SharedArray", + "SharedVector", "Resource", "Color", "PathData", @@ -105,11 +105,11 @@ fn gen_corelib(include_dir: &Path) -> anyhow::Result<()> { cbindgen::Builder::new() .with_config(config.clone()) - .with_src(crate_dir.join("sharedarray.rs")) - .with_after_include("namespace sixtyfps { template struct SharedArray; }") + .with_src(crate_dir.join("sharedvector.rs")) + .with_after_include("namespace sixtyfps { template struct SharedVector; }") .generate() - .context("Unable to generate bindings for sixtyfps_sharedarray_internal.h")? - .write_to_file(include_dir.join("sixtyfps_sharedarray_internal.h")); + .context("Unable to generate bindings for sixtyfps_sharedvector_internal.h")? + .write_to_file(include_dir.join("sixtyfps_sharedvector_internal.h")); let mut properties_config = config.clone(); properties_config.export.exclude.clear(); @@ -221,7 +221,7 @@ fn gen_corelib(include_dir: &Path) -> anyhow::Result<()> { .with_src(crate_dir.join("lib.rs")) .with_include("vtable.h") .with_include("sixtyfps_string.h") - .with_include("sixtyfps_sharedarray.h") + .with_include("sixtyfps_sharedvector.h") .with_include("sixtyfps_properties.h") .with_include("sixtyfps_callbacks.h") .with_include("sixtyfps_resource.h")