• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision155 (tree)
Time2018-11-26 18:21:28
Authorquiret

Log Message

- optimized DynamicTypeSystem::RegisterCommonTypeInterface by placing the typeInterface struct into the new type info generic
- replaced some odd-NULLs

Change Summary

Incremental Difference

--- common/sdk/DynamicTypeSystem.h (revision 154)
+++ common/sdk/DynamicTypeSystem.h (revision 155)
@@ -571,43 +571,43 @@
571571 }
572572
573573 // THREAD-SAFE because memory allocation is THREAD-SAFE and type registration is THREAD-SAFE.
574- template <typename structTypeTypeInterface>
575- inline typeInfoBase* RegisterCommonTypeInterface( const char *typeName, structTypeTypeInterface *tInterface, typeInfoBase *inheritsFrom = nullptr )
574+ template <typename structTypeTypeInterface, typename... constrArgs>
575+ inline typeInfoBase* RegisterCommonTypeInterface( const char *typeName, typeInfoBase *inheritsFrom = nullptr, constrArgs... args )
576576 {
577577 struct typeInfoStruct : public typeInfoBase
578578 {
579+ AINLINE typeInfoStruct( constrArgs... args ) : tInterface( std::forward <constrArgs> ( args )... )
580+ {
581+ return;
582+ }
583+
579584 void Cleanup( void ) override
580585 {
581- eir::static_del_struct <structTypeTypeInterface, allocatorType> ( this->typeSys, this->tInterface );
582586 eir::static_del_struct <typeInfoStruct, allocatorType> ( this->typeSys, this );
583587 }
584588
585- structTypeTypeInterface *tInterface;
589+ structTypeTypeInterface tInterface;
586590 };
591+
592+ typeInfoStruct *tInfo = eir::static_new_struct <typeInfoStruct, allocatorType> ( this, std::forward <constrArgs> ( args )... );
587593
588- typeInfoStruct *tInfo = eir::static_new_struct <typeInfoStruct, allocatorType> ( this );
594+ if ( tInfo == nullptr )
595+ {
596+ return nullptr;
597+ }
589598
590- if ( tInfo )
599+ try
591600 {
592- // IMPORTANT to make class completely valid _before_ it gets into visibility of the whole type system!
593- tInfo->tInterface = tInterface;
601+ SetupTypeInfoBase( tInfo, typeName, &tInfo->tInterface, inheritsFrom );
602+ }
603+ catch( ... )
604+ {
605+ eir::static_del_struct <typeInfoStruct, allocatorType> ( this, tInfo );
594606
595- try
596- {
597- SetupTypeInfoBase( tInfo, typeName, tInterface, inheritsFrom );
598- }
599- catch( ... )
600- {
601- eir::static_del_struct <typeInfoStruct, allocatorType> ( this, tInfo );
602-
603- throw;
604- }
605-
606- return tInfo;
607+ throw;
607608 }
608609
609- eir::static_del_struct <structTypeTypeInterface, allocatorType> ( this, tInterface );
610- return nullptr;
610+ return tInfo;
611611 }
612612
613613 template <typename structType>
@@ -641,29 +641,13 @@
641641 }
642642 };
643643
644- structTypeInterface *tInterface = eir::static_new_struct <structTypeInterface, allocatorType> ( this );
644+ typeInfoBase *newTypeInfo = RegisterCommonTypeInterface <structTypeInterface> ( typeName, inheritsFrom );
645645
646- typeInfoBase *newTypeInfo = nullptr;
647-
648- if ( tInterface )
646+ if ( newTypeInfo )
649647 {
650- try
651- {
652- newTypeInfo = RegisterCommonTypeInterface( typeName, tInterface, inheritsFrom );
653-
654- if ( newTypeInfo )
655- {
656- // WARNING: if you allow construction of types while types register themselves THIS IS A SECURITY ISSUE.
657- // WE DO NOT DO THAT.
658- newTypeInfo->isAbstract = true;
659- }
660- }
661- catch( ... )
662- {
663- eir::static_del_struct <structTypeInterface, allocatorType> ( this, tInterface );
664-
665- throw;
666- }
648+ // WARNING: if you allow construction of types while types register themselves THIS IS A SECURITY ISSUE.
649+ // WE DO NOT DO THAT.
650+ newTypeInfo->isAbstract = true;
667651 }
668652
669653 return newTypeInfo;
@@ -690,6 +674,11 @@
690674 {
691675 struct structTypeInterface : public typeInterface
692676 {
677+ AINLINE structTypeInterface( size_t structSize )
678+ {
679+ this->structSize = structSize;
680+ }
681+
693682 void Construct( void *mem, systemPointer_t *sysPtr, void *construct_params ) const override
694683 {
695684 new (mem) structType( sysPtr, construct_params );
@@ -718,27 +707,7 @@
718707 size_t structSize;
719708 };
720709
721- structTypeInterface *tInterface = eir::static_new_struct <structTypeInterface, allocatorType> ( this );
722-
723- typeInfoBase *newTypeInfo = nullptr;
724-
725- if ( tInterface )
726- {
727- tInterface->structSize = structSize;
728-
729- try
730- {
731- newTypeInfo = RegisterCommonTypeInterface( typeName, tInterface, inheritsFrom );
732- }
733- catch( ... )
734- {
735- eir::static_del_struct <structTypeInterface, allocatorType> ( this, tInterface );
736-
737- throw;
738- }
739- }
740-
741- return newTypeInfo;
710+ return RegisterCommonTypeInterface <structTypeInterface> ( typeName, inheritsFrom, structSize );
742711 }
743712
744713 // THREAD-SAFEty cannot be guarranteed. Use with caution.
@@ -857,10 +826,10 @@
857826 {
858827 struct structTypeInterface : public typeInterface
859828 {
860- inline structTypeInterface( void )
829+ AINLINE structTypeInterface( structTypeMetaInfo *meta_info, bool freeMetaInfo )
861830 {
862- this->meta_info = nullptr;
863- this->freeMetaInfo = false;
831+ this->meta_info = meta_info;
832+ this->freeMetaInfo = freeMetaInfo;
864833 }
865834
866835 inline ~structTypeInterface( void )
@@ -905,30 +874,7 @@
905874 bool freeMetaInfo;
906875 };
907876
908- typeInfoBase *newTypeInfo = nullptr;
909-
910- structTypeInterface *tInterface = eir::static_new_struct <structTypeInterface, allocatorType> ( this );
911-
912- if ( tInterface )
913- {
914- // We inherit the meta information struct.
915- // This means that we will also take care about deallocation.
916- tInterface->meta_info = metaInfo;
917- tInterface->freeMetaInfo = freeMetaInfo;
918-
919- try
920- {
921- newTypeInfo = RegisterCommonTypeInterface( typeName, tInterface, inheritsFrom );
922- }
923- catch( ... )
924- {
925- eir::static_del_struct <structTypeInterface, allocatorType> ( this, tInterface );
926-
927- throw;
928- }
929- }
930-
931- return newTypeInfo;
877+ return RegisterCommonTypeInterface <structTypeInterface> ( typeName, inheritsFrom, metaInfo, freeMetaInfo );
932878 }
933879
934880 private:
--- common/sdk/rwlist.hpp (revision 154)
+++ common/sdk/rwlist.hpp (revision 155)
@@ -23,7 +23,7 @@
2323 #define LIST_INSERT(link, item) ( (item).next = (link).next, (item).prev = &(link), (item).prev->next = &(item), (item).next->prev = &(item) )
2424 #define LIST_REMOVE(link) ( (link).prev->next = (link).next, (link).next->prev = (link).prev )
2525 #define LIST_CLEAR(link) ( (link).prev = &(link), (link).next = &(link) )
26-#define LIST_INITNODE(link) ( (link).prev = NULL, (link).next = NULL )
26+#define LIST_INITNODE(link) ( (link).prev = nullptr, (link).next = nullptr )
2727 #ifdef _DEBUG
2828 #define LIST_EMPTY(link) ( (link).prev == &(link) && (link).next == &(link) )
2929 #else
@@ -40,7 +40,7 @@
4040 template <typename listType> inline void LIST_INSERT( listType& link, listType& item ) { item.next = link.next; item.prev = &link; item.prev->next = &item; item.next->prev = &item; }
4141 template <typename listType> inline void LIST_REMOVE( listType& link ) { link.prev->next = link.next; link.next->prev = link.prev; }
4242 template <typename listType> inline void LIST_CLEAR( listType& link ) { link.prev = &link; link.next = &link; }
43-template <typename listType> inline void LIST_INITNODE( listType& link ) { link.prev = NULL; link.next = NULL; }
43+template <typename listType> inline void LIST_INITNODE( listType& link ) { link.prev = nullptr; link.next = nullptr; }
4444 template <typename listType> inline bool LIST_EMPTY( listType& link ) { return link.prev == &link && link.next == &link; }
4545
4646 #endif //USE_MACRO_LIST
@@ -181,8 +181,8 @@
181181
182182 this->list_iterator = right.list_iterator;
183183
184- right.rootNode = NULL;
185- right.list_iterator = NULL;
184+ right.rootNode = nullptr;
185+ right.list_iterator = nullptr;
186186 }
187187
188188 inline void operator = ( const rwListIterator& right )
Show on old repository browser