summaryrefslogtreecommitdiffstats
path: root/vendor/tinyvec/gen-array-impls.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/tinyvec/gen-array-impls.sh
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tinyvec/gen-array-impls.sh')
-rw-r--r--vendor/tinyvec/gen-array-impls.sh53
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/tinyvec/gen-array-impls.sh b/vendor/tinyvec/gen-array-impls.sh
new file mode 100644
index 000000000..234f771bc
--- /dev/null
+++ b/vendor/tinyvec/gen-array-impls.sh
@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+
+gen_impl() {
+ local len=$1
+ cat <<-END
+ impl<T: Default> Array for [T; $len] {
+ type Item = T;
+ const CAPACITY: usize = $len;
+
+ #[inline(always)]
+ #[must_use]
+ fn as_slice(&self) -> &[T] {
+ &*self
+ }
+
+ #[inline(always)]
+ #[must_use]
+ fn as_slice_mut(&mut self) -> &mut [T] {
+ &mut *self
+ }
+
+ #[inline(always)]
+ fn default() -> Self {
+ [
+ $(for ((i = 0; i < $len; i += 6))
+ do
+ echo -n ' '
+ for ((j = 0; j < 6 && j + i < $len; j++))
+ do
+ echo -n ' T::default(),'
+ done
+ echo
+ done)
+ ]
+ }
+ }
+
+ END
+}
+
+cat <<-END
+ // Generated file, to regenerate run
+ // ./gen-array-impls.sh > src/array/generated_impl.rs
+ // from the repo root
+
+ use super::Array;
+
+ $(for ((i = 0; i <= 33; i++)); do gen_impl $i; done)
+
+ $(for ((i = 64; i <= 4096; i *= 2)); do gen_impl $i; done)
+END
+
+# vim: noet