• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision197 (tree)
Time2019-03-01 16:12:20
Authorquiret

Log Message

- fixed a bug in eir::Vector where the Resize method destroyed constructed elements by over-default-constructing them

Change Summary

Incremental Difference

--- common/sdk/MultiString.h (revision 196)
+++ common/sdk/MultiString.h (revision 197)
@@ -37,19 +37,6 @@
3737 namespace eir
3838 {
3939
40-// Little helper.
41-// Does not really belong here, kek.
42-static inline bool is_system_case_sensitive( void )
43-{
44-#if defined(_WIN32)
45- return false;
46-#elif defined(__linux__)
47- return true;
48-#else
49-#error Unknown platform
50-#endif
51-}
52-
5340 // String container that is encoding-transparent.
5441 // Supports both unicode and ANSI, can run case-sensitive or opposite.
5542 #define MSTR_TEMPLARGS \
--- common/sdk/UniChar.h (revision 196)
+++ common/sdk/UniChar.h (revision 197)
@@ -67,7 +67,7 @@
6767 private:
6868 static AINLINE bool is_zero( charType cp )
6969 {
70- return ( cp == charType() );
70+ return ( cp == (charType)0 );
7171 }
7272
7373 public:
--- common/sdk/Vector.h (revision 196)
+++ common/sdk/Vector.h (revision 197)
@@ -847,7 +847,7 @@
847847 }
848848
849849 // Simple method for single insertion.
850- inline void Insert( size_t insertPos, structType&& value )
850+ inline void InsertMove( size_t insertPos, structType&& value )
851851 {
852852 this->InsertMove( insertPos, &value, 1 );
853853 }
@@ -854,7 +854,7 @@
854854
855855 inline void Insert( size_t insertPos, const structType& value )
856856 {
857- this->InsertMove( insertPos, &value, 1 );
857+ this->Insert( insertPos, &value, 1 );
858858 }
859859
860860 private:
@@ -1009,17 +1009,33 @@
10091009 }
10101010
10111011 size_t oldCount = this->data.data_count;
1012+
1013+ if ( oldCount == newCount )
1014+ return;
1015+
10121016 size_t newRequiredSize = newCount * sizeof(structType);
10131017
10141018 if ( structType *useData = this->data.data_entries )
10151019 {
1016- bool gotToResize = this->data.allocData.Resize( this, useData, newRequiredSize );
1020+ if ( oldCount > newCount )
1021+ {
1022+ // We assume that we can always shrink.
1023+ // First delete the stuff.
1024+ for ( size_t iter = newCount; iter < oldCount; iter++ )
1025+ {
1026+ ( useData + iter )->~structType();
1027+ }
10171028
1018- if ( gotToResize )
1029+ shrink_backed_memory( useData, newCount );
1030+ return;
1031+ }
1032+ else // ( oldCount < newCount )
10191033 {
1020- if ( oldCount < newCount )
1034+ bool gotToResize = this->data.allocData.Resize( this, useData, newRequiredSize );
1035+
1036+ if ( gotToResize )
10211037 {
1022- size_t create_idx = 0;
1038+ size_t create_idx = oldCount;
10231039
10241040 try
10251041 {
@@ -1046,12 +1062,12 @@
10461062
10471063 throw;
10481064 }
1049- }
10501065
1051- // Success.
1052- this->data.data_count = newCount;
1066+ // Success.
1067+ this->data.data_count = newCount;
10531068
1054- return;
1069+ return;
1070+ }
10551071 }
10561072 }
10571073
Show on old repository browser