bulk code format fix (#8707)

This commit is contained in:
Derek Bailey
2025-09-23 21:50:27 -07:00
committed by GitHub
parent 0e047869da
commit caf3b494db
559 changed files with 38871 additions and 31276 deletions

View File

@@ -48,10 +48,7 @@ impl<'a> MapBuilder<'a> {
self.builder.push_key(key);
// Nested vector.
let start = Some(self.builder.values.len());
VectorBuilder {
builder: self.builder,
start,
}
VectorBuilder { builder: self.builder, start }
}
/// Starts a nested map which that will be pushed onto this map
/// with key `key` when it is dropped.
@@ -63,10 +60,7 @@ impl<'a> MapBuilder<'a> {
self.builder.push_key(key);
// Nested map.
let start = Some(self.builder.values.len());
MapBuilder {
builder: self.builder,
start,
}
MapBuilder { builder: self.builder, start }
}
/// `end_map` sorts the map by key and writes it to the buffer. This happens anyway
/// when the map builder is dropped.

View File

@@ -35,12 +35,8 @@ macro_rules! push_slice {
S: AsRef<[T]>,
{
let mut value = Value::$new_vec(xs.as_ref().len());
let mut width = xs
.as_ref()
.iter()
.map(|x| BitWidth::from((*x).into()))
.max()
.unwrap_or_default();
let mut width =
xs.as_ref().iter().map(|x| BitWidth::from((*x).into())).max().unwrap_or_default();
if !value.is_fixed_length_vector() {
let length = Value::UInt(xs.as_ref().len() as u64);
width = std::cmp::max(width, length.width_or_child_width());
@@ -135,16 +131,8 @@ impl Default for Builder {
impl<'a> Builder {
pub fn new(opts: BuilderOptions) -> Self {
let key_pool = if opts.contains(BuilderOptions::SHARE_KEYS) {
Some(vec![])
} else {
None
};
Builder {
key_pool,
values: Vec::new(),
buffer: Vec::new(),
}
let key_pool = if opts.contains(BuilderOptions::SHARE_KEYS) { Some(vec![]) } else { None };
Builder { key_pool, values: Vec::new(), buffer: Vec::new() }
}
/// Shows the internal flexbuffer. It will either be empty or populated with the most
/// recently built flexbuffer.
@@ -167,10 +155,7 @@ impl<'a> Builder {
}
}
fn push_key(&mut self, key: &str) {
debug_assert!(
key.bytes().all(|b| b != b'\0'),
"Keys must not have internal nulls."
);
debug_assert!(key.bytes().all(|b| b != b'\0'), "Keys must not have internal nulls.");
// Search key pool if there is one.
let found = self.key_pool.as_ref().map(|pool| {
pool.binary_search_by(|&CachedKey(addr)| {
@@ -217,11 +202,7 @@ impl<'a> Builder {
store_value(&mut self.buffer, length, width);
let address = self.buffer.len();
self.buffer.extend_from_slice(xs);
Value::Reference {
fxb_type: FlexBufferType::Blob,
address,
child_width: width,
}
Value::Reference { fxb_type: FlexBufferType::Blob, address, child_width: width }
}
fn push_str(&mut self, x: &str) {
let mut string = self.store_blob(x.as_bytes());
@@ -261,18 +242,12 @@ impl<'a> Builder {
/// The exact Flexbuffer vector type is dynamically inferred.
pub fn start_vector(&'a mut self) -> VectorBuilder<'a> {
self.reset();
VectorBuilder {
builder: self,
start: None,
}
VectorBuilder { builder: self, start: None }
}
/// Resets the builder and builds a new flexbuffer with a map at the root.
pub fn start_map(&'a mut self) -> MapBuilder<'a> {
self.reset();
MapBuilder {
builder: self,
start: None,
}
MapBuilder { builder: self, start: None }
}
/// Resets the builder and builds a new flexbuffer with the pushed value at the root.
pub fn build_singleton<P: Pushable>(&mut self, p: P) {

View File

@@ -49,19 +49,13 @@ impl FlexbufferSerializer {
Ok(())
}
fn start_vector(&mut self) {
let previous_end = if self.nesting.is_empty() {
None
} else {
Some(self.builder.values.len())
};
let previous_end =
if self.nesting.is_empty() { None } else { Some(self.builder.values.len()) };
self.nesting.push(previous_end);
}
fn start_map(&mut self) {
let previous_end = if self.nesting.is_empty() {
None
} else {
Some(self.builder.values.len())
};
let previous_end =
if self.nesting.is_empty() { None } else { Some(self.builder.values.len()) };
self.nesting.push(previous_end);
}
fn end_vector(&mut self) -> Result<(), Error> {

View File

@@ -47,26 +47,10 @@ macro_rules! new_typed_vector {
let address = 0;
let child_width = W8;
match n {
2 => Value::Reference {
address,
child_width,
fxb_type: $v2,
},
3 => Value::Reference {
address,
child_width,
fxb_type: $v3,
},
4 => Value::Reference {
address,
child_width,
fxb_type: $v4,
},
_ => Value::Reference {
address,
child_width,
fxb_type: $vn,
},
2 => Value::Reference { address, child_width, fxb_type: $v2 },
3 => Value::Reference { address, child_width, fxb_type: $v3 },
4 => Value::Reference { address, child_width, fxb_type: $v4 },
_ => Value::Reference { address, child_width, fxb_type: $vn },
}
}
};
@@ -74,40 +58,14 @@ macro_rules! new_typed_vector {
impl Value {
pub fn new_vector() -> Self {
Value::Reference {
address: 0,
child_width: W8,
fxb_type: Vector,
}
Value::Reference { address: 0, child_width: W8, fxb_type: Vector }
}
pub fn new_map() -> Self {
Value::Reference {
address: 0,
child_width: W8,
fxb_type: Map,
}
Value::Reference { address: 0, child_width: W8, fxb_type: Map }
}
new_typed_vector!(
new_int_vector,
VectorInt2,
VectorInt3,
VectorInt4,
VectorInt
);
new_typed_vector!(
new_uint_vector,
VectorUInt2,
VectorUInt3,
VectorUInt4,
VectorUInt
);
new_typed_vector!(
new_float_vector,
VectorFloat2,
VectorFloat3,
VectorFloat4,
VectorFloat
);
new_typed_vector!(new_int_vector, VectorInt2, VectorInt3, VectorInt4, VectorInt);
new_typed_vector!(new_uint_vector, VectorUInt2, VectorUInt3, VectorUInt4, VectorUInt);
new_typed_vector!(new_float_vector, VectorFloat2, VectorFloat3, VectorFloat4, VectorFloat);
pub fn fxb_type(&self) -> FlexBufferType {
match *self {
Value::Null => Null,
@@ -264,11 +222,7 @@ where
// Note that VectorString is deprecated for writing
_ => return Value::new_vector(),
};
Value::Reference {
address: 0,
child_width: W8,
fxb_type: vector_type,
}
Value::Reference { address: 0, child_width: W8, fxb_type: vector_type }
}
#[inline]
@@ -299,9 +253,6 @@ pub fn store_value(buffer: &mut Vec<u8>, mut value: Value, width: BitWidth) {
_ => unreachable!("Variant not considered: {:?}", value),
};
write_result.unwrap_or_else(|err| {
panic!(
"Error writing value {:?} with width {:?}: {:?}",
value, width, err
)
panic!("Error writing value {:?} with width {:?}: {:?}", value, width, err)
});
}

View File

@@ -38,19 +38,13 @@ impl<'a> VectorBuilder<'a> {
#[inline]
pub fn start_vector(&mut self) -> VectorBuilder {
let start = Some(self.builder.values.len());
VectorBuilder {
builder: self.builder,
start,
}
VectorBuilder { builder: self.builder, start }
}
/// Starts a nested map that will be pushed onto this vector when it is dropped.
#[inline]
pub fn start_map(&mut self) -> MapBuilder {
let start = Some(self.builder.values.len());
MapBuilder {
builder: self.builder,
start,
}
MapBuilder { builder: self.builder, start }
}
/// `end_vector` determines the type of the vector and writes it to the buffer.
/// This will happen automatically if the VectorBuilder is dropped.