Commit fdfc470b authored by cutealien's avatar cutealien

Improving array::insert speed by kicking out lots of memory construction...

Improving array::insert speed by kicking out lots of memory construction calls, but hopefull still leaving all the important ones in places. Does double the speed but is still twice as slow as std::insert unfortunately.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3064 dfc29bdd-3216-0410-991c-e03cc46cb475
parent a0b9cea7
...@@ -164,18 +164,25 @@ public: ...@@ -164,18 +164,25 @@ public:
} }
else else
{ {
// move array content and construct new element // element inserted not at end
// first move end one up if ( used > index )
for (u32 i=used; i>index; --i)
{ {
if (i<used) // create one new element at the end
allocator.destruct(&data[i]); allocator.construct(&data[used], data[used-1]);
allocator.construct(&data[i], data[i-1]); // data[i] = data[i-1];
// move the rest of the array content
for (u32 i=used-1; i>index; --i)
{
data[i] = data[i-1];
}
// insert the new element
data[index] = element;
}
else
{
// insert the new element to the end
allocator.construct(&data[index], element);
} }
// then add new element
if (used > index)
allocator.destruct(&data[index]);
allocator.construct(&data[index], element); // data[index] = element;
} }
// set to false as we don't know if we have the comparison operators // set to false as we don't know if we have the comparison operators
is_sorted = false; is_sorted = false;
......
Test suite pass at GMT Mon Dec 21 13:21:36 2009 Test suite pass at GMT Mon Dec 21 20:14:01 2009
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment