55namespace csp
66{
77
8- StructField::StructField ( CspTypePtr type, const std::string & fieldname,
8+ StructField::StructField ( CspTypePtr type, const std::string & fieldname,
99 size_t size, size_t alignment ) :
1010 m_fieldname ( fieldname ),
1111 m_offset ( 0 ),
@@ -18,15 +18,15 @@ StructField::StructField( CspTypePtr type, const std::string & fieldname,
1818{
1919}
2020
21- /* StructMeta
21+ /* StructMeta
2222
2323A note on member layout. Meta will order objects in the following order:
2424- non-native fields ( ie PyObjectPtr for the python dialect )
2525- native fields sorted in order
2626- set/unset bitmask bytes ( 1 byte per 8 fields )
2727
2828Derived structs will simply append to the layout of the base struct, properly padding between classes to align
29- its fields properly.
29+ its fields properly.
3030This layout is imposed on Struct instances. Since Struct needs refcount and meta * fields, for convenience they are stored
3131*before* a Struct's "this" pointer as hidden data. This way struct ptrs can be passed into StructMeta without
3232and adjustments required for the hidden fields
@@ -47,7 +47,7 @@ StructMeta::StructMeta( const std::string & name, const Fields & fields,
4747 // decided to place them at the start cause they are most likely size of ptr or greater
4848
4949 m_fieldnames.reserve ( m_fields.size () );
50- for ( size_t i = 0 ; i < m_fields.size (); i++ )
50+ for ( size_t i = 0 ; i < m_fields.size (); i++ )
5151 m_fieldnames.emplace_back ( m_fields[i] -> fieldname () );
5252
5353 std::sort ( m_fields.begin (), m_fields.end (), []( auto && a, auto && b )
@@ -93,7 +93,7 @@ StructMeta::StructMeta( const std::string & name, const Fields & fields,
9393 m_isFullyNative = m_isPartialNative && ( m_base ? m_base -> isNative () : true );
9494
9595 // Setup masking bits for our fields
96- // NOTE we can be more efficient by sticking masks into any potential alignment gaps, dont want to spend time on it
96+ // NOTE we can be more efficient by sticking masks into any potential alignment gaps, dont want to spend time on it
9797 // at this point
9898 m_maskSize = !m_fields.empty () ? 1 + ( ( m_fields.size () - 1 ) / 8 ) : 0 ;
9999 m_size = offset + m_maskSize;
@@ -116,7 +116,7 @@ StructMeta::StructMeta( const std::string & name, const Fields & fields,
116116 {
117117 m_fields.insert ( m_fields.begin (), m_base -> m_fields.begin (), m_base -> m_fields.end () );
118118 m_fieldnames.insert ( m_fieldnames.begin (), m_base -> m_fieldnames.begin (), m_base -> m_fieldnames.end () );
119-
119+
120120 m_firstPartialField = m_base -> m_fields.size ();
121121 m_firstNativePartialField += m_base -> m_fields.size ();
122122 m_fieldMap = m_base -> m_fieldMap;
@@ -145,7 +145,7 @@ Struct * StructMeta::createRaw() const
145145 initialize ( s );
146146
147147 if ( m_default )
148- s -> copyFrom ( m_default.get () ); // TODO change to deepcopy after this fix is released
148+ s -> deepcopyFrom ( m_default.get () );
149149
150150 return s;
151151}
@@ -212,7 +212,7 @@ void StructMeta::initialize( Struct * s ) const
212212 }
213213
214214 memset ( reinterpret_cast <std::byte*>(s) + m_nativeStart, 0 , partialNativeSize () );
215-
215+
216216 if ( !m_isPartialNative )
217217 {
218218 for ( size_t idx = m_firstPartialField; idx < m_firstNativePartialField; ++idx )
@@ -221,7 +221,7 @@ void StructMeta::initialize( Struct * s ) const
221221 static_cast <NonNativeStructField*>( field ) -> initialize ( s );
222222 }
223223 }
224-
224+
225225 if ( m_base )
226226 m_base -> initialize ( s );
227227}
@@ -231,9 +231,9 @@ void StructMeta::copyFrom( const Struct * src, Struct * dest )
231231 if ( unlikely ( src == dest ) )
232232 return ;
233233
234- if ( dest -> meta () != src -> meta () &&
234+ if ( dest -> meta () != src -> meta () &&
235235 !StructMeta::isDerivedType ( src -> meta (), dest -> meta () ) )
236- CSP_THROW ( TypeError, " Attempting to copy from struct type '" << src -> meta () -> name () << " ' to struct type '" << dest -> meta () -> name ()
236+ CSP_THROW ( TypeError, " Attempting to copy from struct type '" << src -> meta () -> name () << " ' to struct type '" << dest -> meta () -> name ()
237237 << " '. copy_from may only be used to copy from same type or derived types" );
238238
239239 dest -> meta () -> copyFromImpl ( src, dest, false );
@@ -280,7 +280,7 @@ void StructMeta::copyFromImpl( const Struct * src, Struct * dest, bool deepcopy
280280 // note that partialNative will include the mask bytes - this sets the native part and the mask
281281 memcpy ( reinterpret_cast <std::byte*>(dest) + m_nativeStart, reinterpret_cast <const std::byte*>(src) + m_nativeStart,
282282 partialNativeSize () );
283-
283+
284284 if ( m_base )
285285 m_base -> copyFromImpl ( src, dest, deepcopy );
286286 }
@@ -291,13 +291,13 @@ void StructMeta::updateFrom( const Struct * src, Struct * dest )
291291 if ( unlikely ( src == dest ) )
292292 return ;
293293
294- if ( dest -> meta () != src -> meta () &&
294+ if ( dest -> meta () != src -> meta () &&
295295 !StructMeta::isDerivedType ( src -> meta (), dest -> meta () ) )
296- CSP_THROW ( TypeError, " Attempting to update from struct type '" << src -> meta () -> name () << " ' to struct type '" << dest -> meta () -> name ()
296+ CSP_THROW ( TypeError, " Attempting to update from struct type '" << src -> meta () -> name () << " ' to struct type '" << dest -> meta () -> name ()
297297 << " '. update_from may only be used to update from same type or derived types" );
298298
299299 dest -> meta () -> updateFromImpl ( src, dest );
300- }
300+ }
301301
302302void StructMeta::updateFromImpl ( const Struct * src, Struct * dest ) const
303303{
@@ -328,7 +328,7 @@ bool StructMeta::isEqual( const Struct * x, const Struct * y ) const
328328
329329 // Note the curent use of memcpy for native types. This can cause issues on double comparisons
330330 // esp if expecting NaN == NaN to be false, and when comparing -0.0 to +0.0.. may want to revisit
331- // We we do we may as well remove the basepadding copy
331+ // We we do we may as well remove the basepadding copy
332332 if ( isNative () )
333333 return memcmp ( x, y, size () ) == 0 ;
334334
@@ -341,7 +341,7 @@ bool StructMeta::isEqual( const Struct * x, const Struct * y ) const
341341 for ( size_t idx = m_firstPartialField; idx < m_firstNativePartialField; ++idx )
342342 {
343343 auto * field = m_fields[ idx ].get ();
344-
344+
345345 if ( field -> isSet ( x ) != field -> isSet ( y ) )
346346 return false ;
347347
@@ -386,19 +386,19 @@ size_t StructMeta::hash( const Struct * x ) const
386386 " Exceeded max recursion depth of " << MAX_RECURSION_DEPTH << " in " << name () << " ::hash(), cannot hash cyclic data structure" );
387387
388388 hash ^= csp::hash::hash_bytes ( x + m_nativeStart, partialNativeSize () );
389-
389+
390390 if ( !m_isPartialNative )
391391 {
392392 for ( size_t idx = m_firstPartialField; idx < m_firstNativePartialField; ++idx )
393393 {
394394 auto * field = m_fields[ idx ].get ();
395-
395+
396396 // we dont incorporate unset fields, bitmask will cover them
397397 if ( field -> isSet ( x ) )
398398 hash ^= static_cast <NonNativeStructField*>( field ) -> hash ( x );
399399 }
400400 }
401-
401+
402402 if ( m_base )
403403 hash ^= std::hash<uint64_t >()( (uint64_t ) m_base.get () ) ^ m_base -> hash ( x );
404404
@@ -414,18 +414,18 @@ void StructMeta::clear( Struct * s ) const
414414 }
415415
416416 memset ( reinterpret_cast <std::byte*>(s) + m_nativeStart, 0 , partialNativeSize () );
417-
417+
418418 if ( !m_isPartialNative )
419419 {
420420 for ( size_t idx = m_firstPartialField; idx < m_firstNativePartialField; ++idx )
421421 {
422422 auto * field = m_fields[ idx ].get ();
423-
423+
424424 if ( field -> isSet ( s ) )
425425 static_cast <NonNativeStructField*>( field ) -> clearValue ( s );
426426 }
427427 }
428-
428+
429429 if ( m_base )
430430 m_base -> clear ( s );
431431}
@@ -466,7 +466,7 @@ void StructMeta::destroy( Struct * s ) const
466466 static_cast <NonNativeStructField*>( field ) -> destroy ( s );
467467 }
468468 }
469-
469+
470470 if ( m_base )
471471 m_base -> destroy ( s );
472472}
0 commit comments