Improve DqnArray::Insert
This commit is contained in:
parent
6df3b32f4e
commit
4ee040b6b0
32
DqnUnitTest.sln
Normal file
32
DqnUnitTest.sln
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27428.2037
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{911E67C6-3D85-4FCE-B560-20A9C3E3FF48}") = "DqnUnitTest", "bin\DqnUnitTest.exe", "{F1606403-E704-4C35-8354-8E33DE4F5CCF}"
|
||||
ProjectSection(DebuggerProjectSystem) = preProject
|
||||
PortSupplier = 00000000-0000-0000-0000-000000000000
|
||||
Executable = F:\dev\dqn\bin\DqnUnitTest.exe
|
||||
RemoteMachine = THAI-XPS13
|
||||
StartingDirectory = F:\dev\dqn\
|
||||
Environment = Default
|
||||
LaunchingEngine = 00000000-0000-0000-0000-000000000000
|
||||
UseLegacyDebugEngines = No
|
||||
LaunchSQLEngine = No
|
||||
AttachLaunchAction = No
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{F1606403-E704-4C35-8354-8E33DE4F5CCF}.Release|x64.ActiveCfg = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {8DD71C86-534C-4A9C-A217-CBA13DE8DA5A}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
19
dqn.h
19
dqn.h
@ -1170,8 +1170,7 @@ private:
|
||||
|
||||
template<typename T> T *DqnArray<T>::Insert(isize index, T const *v, isize numItems)
|
||||
{
|
||||
index = DQN_MIN(DQN_MAX(index, 0), count);
|
||||
isize const off = (data + index) - data;
|
||||
index = DQN_MIN(DQN_MAX(index, 0), count);
|
||||
isize const newCount = count + numItems;
|
||||
|
||||
if (newCount >= max && !Reserve(GrowCapacity_(newCount)))
|
||||
@ -1179,15 +1178,16 @@ template<typename T> T *DqnArray<T>::Insert(isize index, T const *v, isize numIt
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
count = newCount;
|
||||
T *start = data + off;
|
||||
if (off < count)
|
||||
memmove(start + numItems, start, ((usize)count - (usize)off) * sizeof(T));
|
||||
T *src = data + index;
|
||||
T *dest = src + numItems;
|
||||
if (src < dest)
|
||||
memmove(dest, src, ((data + count) - src) * sizeof(T));
|
||||
|
||||
for (isize i = 0; i < numItems; i++)
|
||||
data[off + i] = v[i];
|
||||
src[i] = v[i];
|
||||
|
||||
return data + off;
|
||||
count = newCount;
|
||||
return src;
|
||||
}
|
||||
|
||||
template <typename T> void DqnArray<T>::EraseStable(isize index)
|
||||
@ -2163,7 +2163,7 @@ struct DqnFixedString
|
||||
int VSprintf (char const *fmt, va_list argList);
|
||||
int VSprintfAppend(char const *fmt, va_list argList);
|
||||
|
||||
void Clear (Dqn::ZeroClear clear = Dqn::ZeroClear::No) { if (clear == Dqn::ZeroClear::Yes) DqnMem_Set(str, 0, MAX); this = {}; }
|
||||
void Clear (Dqn::ZeroClear clear = Dqn::ZeroClear::No) { if (clear == Dqn::ZeroClear::Yes) DqnMem_Set(str, 0, MAX); *this = {}; }
|
||||
};
|
||||
|
||||
template <unsigned int MAX>
|
||||
@ -8802,7 +8802,6 @@ DqnLockGuard::~DqnLockGuard()
|
||||
|
||||
// XPlatform > #DqnJobQueue
|
||||
// =================================================================================================
|
||||
|
||||
typedef void *DqnThreadCallbackInternal(void *threadParam);
|
||||
usize DQN_JOB_QUEUE_INTERNAL_THREAD_DEFAULT_STACK_SIZE = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user