From 93fc31e9ea9043108c4dcb469e1d443cea8d8e24 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Tue, 19 Nov 2024 19:07:48 +0100 Subject: [PATCH] ff: refactor cubic extension (#881) --- ff/src/fields/models/cubic_extension.rs | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/ff/src/fields/models/cubic_extension.rs b/ff/src/fields/models/cubic_extension.rs index 72eea3bcd..9c3e05181 100644 --- a/ff/src/fields/models/cubic_extension.rs +++ b/ff/src/fields/models/cubic_extension.rs @@ -632,7 +632,7 @@ impl CanonicalDeserializeWithFlags for CubicExtField

{ let c0 = CanonicalDeserialize::deserialize_compressed(&mut reader)?; let c1 = CanonicalDeserialize::deserialize_compressed(&mut reader)?; let (c2, flags) = CanonicalDeserializeWithFlags::deserialize_with_flags(&mut reader)?; - Ok((CubicExtField::new(c0, c1, c2), flags)) + Ok((Self::new(c0, c1, c2), flags)) } } @@ -651,13 +651,10 @@ impl CanonicalDeserialize for CubicExtField

{ compress: Compress, validate: Validate, ) -> Result { - let c0: P::BaseField = - CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; - let c1: P::BaseField = - CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; - let c2: P::BaseField = - CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; - Ok(CubicExtField::new(c0, c1, c2)) + let c0 = CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; + let c1 = CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; + let c2 = CanonicalDeserialize::deserialize_with_mode(&mut reader, compress, validate)?; + Ok(Self::new(c0, c1, c2)) } } @@ -666,15 +663,9 @@ where P::BaseField: ToConstraintField, { fn to_field_elements(&self) -> Option> { - let mut res = Vec::new(); - let mut c0_elems = self.c0.to_field_elements()?; - let mut c1_elems = self.c1.to_field_elements()?; - let mut c2_elems = self.c2.to_field_elements()?; - - res.append(&mut c0_elems); - res.append(&mut c1_elems); - res.append(&mut c2_elems); - + let mut res = self.c0.to_field_elements()?; + res.extend(self.c1.to_field_elements()?); + res.extend(self.c2.to_field_elements()?); Some(res) } }