restructued solution and improved string

This commit is contained in:
Luis Stanglmeier 2022-01-28 16:03:55 +01:00
parent 4f9b04c049
commit 5bbed99591
12 changed files with 28 additions and 26 deletions

View file

@ -1,9 +1,9 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio 15
VisualStudioVersion = 16.0.31624.102 VisualStudioVersion = 15.0.28307.1778
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LSString", "LSString\LSString.vcxproj", "{5FE98B77-3558-4384-BDAF-82AC8B69B752}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LSFramework", "LSFramework\LSFramework.vcxproj", "{5FE98B77-3558-4384-BDAF-82AC8B69B752}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View file

@ -23,33 +23,33 @@
<ProjectGuid>{5FE98B77-3558-4384-BDAF-82AC8B69B752}</ProjectGuid> <ProjectGuid>{5FE98B77-3558-4384-BDAF-82AC8B69B752}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>String</RootNamespace> <RootNamespace>String</RootNamespace>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
<ProjectName>LSString</ProjectName> <ProjectName>LSFramework</ProjectName>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>

View file

@ -6,11 +6,9 @@ LSString::LSString(const char* pData)
: m_uiLength(StringLength(pData)) : m_uiLength(StringLength(pData))
, m_uiCapacity(StringLength(pData)) , m_uiCapacity(StringLength(pData))
{ {
if (!pData) return;
m_pData = new char[m_uiLength + 1]; m_pData = new char[m_uiLength + 1];
memset(m_pData, 0, m_uiLength + 1); memset(m_pData, 0, m_uiLength + 1);
memcpy(m_pData, pData, m_uiLength); if(pData) memcpy(m_pData, pData, m_uiLength);
} }
//----------------------------------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------------------------------
@ -54,21 +52,21 @@ void LSString::Insert(const char* pData, size_t uiPos)
{ {
if (!pData) return; if (!pData) return;
size_t uilength = StringLength(pData); size_t zLength = StringLength(pData);
size_t uiNewLength = m_uiLength + uilength; size_t zNewLength = m_uiLength + zLength;
while (uiNewLength > m_uiCapacity) while (zNewLength > m_uiCapacity)
{ {
IncreaseCapacity(uiNewLength); IncreaseCapacity(zNewLength);
} }
char* pLeft = m_pData + uiPos; char* pLeft = m_pData + uiPos;
char* pRight = m_pData + uiPos + uilength; char* pRight = m_pData + uiPos + zLength;
memcpy(pRight, m_pData + uiPos, m_uiLength - uiPos); memcpy(pRight, m_pData + uiPos, m_uiLength - uiPos);
memcpy(pLeft, pData, uilength); memcpy(pLeft, pData, zLength);
m_uiLength = uiNewLength; m_uiLength = zNewLength;
} }
//----------------------------------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------------------------------
@ -86,7 +84,7 @@ void LSString::Append(const std::string& sRhs)
//----------------------------------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------------------------------
void LSString::Append(const char* pData) void LSString::Append(const char* pData)
{ {
Insert(pData, StringLength(pData)); Insert(pData, m_uiLength);
} }
//----------------------------------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------------------------------

View file

@ -16,5 +16,6 @@ Timer::~Timer()
auto end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimePoint).time_since_epoch().count(); auto end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimePoint).time_since_epoch().count();
auto duration = end - start; auto duration = end - start;
std::cout << "Duration in Microseconds: " << duration << " (" << duration * 0.001 << " ms)" << std::endl; printf("Duration in Microseconds: %2d (%.3f ms)\n", duration, (duration * 0.001));
//std::cout << "Duration in Microseconds: " << duration << " (" << duration * 0.001 << " ms)" << std::endl;
} }

View file

@ -4,21 +4,21 @@
#include "Timer.h" #include "Timer.h"
#define RUNS 50U #define RUNS 50U
#define PAYLOAD "187" #define PAYLOAD "1873612578869"
int main() int main()
{ {
// - STRING // - STRING
{ {
printf("LSString:\n"); printf("---LSString---\n");
printf("Number of runs: %d:\n", (int)RUNS); printf("Number of runs: %d\n", (int)RUNS);
Timer ttt; Timer ttt;
for (size_t zRun = 1; zRun <= RUNS; zRun++) for (size_t zRun = 1; zRun <= RUNS; zRun++)
{ {
printf("Run: %2d: ", (int)zRun); printf("Run: %2d: ", static_cast<int>(zRun));
Timer tt; Timer tt;
LSString s("361"); LSString s(nullptr);
for (size_t z = 0; z < RUNS * 187; z++) for (size_t z = 0; z < RUNS * 187; z++)
{ {
@ -29,6 +29,9 @@ int main()
// - LIST // - LIST
{ {
printf("---LSList---\n");
printf("Number of runs: %d\n", (int) RUNS);
Timer ttt;
int i1 = 1187; int i1 = 1187;
int i2 = 2361; int i2 = 2361;
int i3 = 3257; int i3 = 3257;