@@ -254,25 +254,24 @@ impl<E: Engine, C: Circuit<E>, A: HostAllocator> FflonkDeviceSetup<E, C, A> {
254254 assert_eq ! ( num_polys, 5 ) ;
255255 let mut main_gate_selector_monomials = vec ! [ ] ;
256256 for _ in 0 ..num_polys {
257- let num_values = reader. read_u64 :: < BigEndian > ( ) ?;
258- let mut coeffs = Vec :: with_capacity_in ( num_values as usize , A :: default ( ) ) ;
259- for _ in 0 ..num_values {
260- let el = read_fr ( & mut reader) ?;
261- coeffs. push ( el) ;
262- }
257+ let coeffs = read_raw_fr_vec :: < _ , _ , A > ( & mut reader) ?;
263258 main_gate_selector_monomials. push ( coeffs) ;
264259 }
265260
266261 let num_polys = reader. read_u64 :: < BigEndian > ( ) ?;
267262 assert_eq ! ( num_polys, 3 ) ;
268263 let mut variable_indexes = vec ! [ ] ;
269264 for _ in 0 ..num_polys {
270- let num_values = reader. read_u64 :: < BigEndian > ( ) ?;
271- let mut indexes = Vec :: with_capacity_in ( num_values as usize , A :: default ( ) ) ;
272- for _ in 0 ..num_values {
273- let el = reader. read_u32 :: < BigEndian > ( ) ?;
274- indexes. push ( el) ;
275- }
265+ let num_values = reader. read_u64 :: < BigEndian > ( ) ? as usize ;
266+ let mut indexes = Vec :: with_capacity_in ( num_values, A :: default ( ) ) ;
267+ let indexes_buf = unsafe {
268+ indexes. set_len ( num_values) ;
269+ std:: slice:: from_raw_parts_mut (
270+ indexes. as_mut_ptr ( ) as * mut u8 ,
271+ num_values * std:: mem:: size_of :: < u32 > ( ) ,
272+ )
273+ } ;
274+ reader. read_exact ( indexes_buf) ?;
276275 variable_indexes. push ( indexes) ;
277276 }
278277
@@ -293,14 +292,18 @@ impl<E: Engine, C: Circuit<E>, A: HostAllocator> FflonkDeviceSetup<E, C, A> {
293292 use byteorder:: { BigEndian , WriteBytesExt } ;
294293 writer. write_u64 :: < BigEndian > ( self . main_gate_selector_monomials . len ( ) as u64 ) ?;
295294 for mon in self . main_gate_selector_monomials . iter ( ) {
296- write_fr_vec ( & mon, & mut writer) ?;
295+ write_raw_fr_slice ( & mon, & mut writer) ?;
297296 }
298297 writer. write_u64 :: < BigEndian > ( self . variable_indexes . len ( ) as u64 ) ?;
299298 for col in self . variable_indexes . iter ( ) {
300299 writer. write_u64 :: < BigEndian > ( col. len ( ) as u64 ) ?;
301- for el in col {
302- writer. write_u32 :: < BigEndian > ( * el) ?;
303- }
300+ let buf = unsafe {
301+ std:: slice:: from_raw_parts (
302+ col. as_ptr ( ) as * mut u8 ,
303+ col. len ( ) * std:: mem:: size_of :: < u32 > ( ) ,
304+ )
305+ } ;
306+ writer. write_all ( buf) ?;
304307 }
305308 write_curve_affine ( & self . c0_commitment , & mut writer) ?;
306309 write_curve_affine ( & self . g2_elems [ 0 ] , & mut writer) ?;
@@ -320,9 +323,7 @@ pub fn read_raw_fr_vec<F: PrimeField, R: std::io::Read, A: Allocator + Default>(
320323 values. as_mut_ptr ( ) as * mut u8 ,
321324 num_values * std:: mem:: size_of :: < F > ( ) ,
322325 ) ;
323- // src.read_exact(buf)?;
324- let mut dst = & mut buf[ ..] ;
325- std:: io:: copy ( & mut src, & mut dst) ?;
326+ src. read_exact ( buf) ?;
326327 }
327328
328329 Ok ( values)
@@ -341,9 +342,7 @@ pub fn write_raw_fr_slice<F: PrimeField, W: std::io::Write>(
341342 src_values. as_ptr ( ) as * mut u8 ,
342343 num_values * std:: mem:: size_of :: < F > ( ) ,
343344 ) ;
344- let mut reader = & buf[ ..] ;
345- // dst.write_all(buf)?;
346- std:: io:: copy ( & mut reader, & mut dst) ?;
345+ dst. write_all ( buf) ?;
347346 }
348347
349348 Ok ( ( ) )
0 commit comments