commit 2025-09-19 22:55 Optimize Replace() in ZtCStringBase
This commit is contained in:
@ -91,13 +91,12 @@ namespace ZNsMain
|
||||
##########################################################*/
|
||||
|
||||
|
||||
template<typename TPosList> ZCStringStd& ReplaceToOutByPosList
|
||||
template<typename TPosList> ZCStringStd& ReplaceByPosList
|
||||
(
|
||||
TPosList& AR_CPosList ,
|
||||
TypeCPChar APC_Replace ,
|
||||
TypeLength AL_Replace ,
|
||||
TypeLength AL_Searched ,
|
||||
ZCStringStd& ARR_SaveOut
|
||||
TypeLength AL_Searched
|
||||
)
|
||||
/*##########################################################*/
|
||||
{
|
||||
@ -118,6 +117,12 @@ namespace ZNsMain
|
||||
TypeLength VL_SearchedPos= 0 ;
|
||||
TypeLength VL_SearchedPre= 0 ; // VL_SearchedPos 의 이전 값
|
||||
|
||||
TypePChar VPC_MoveStart = 0 ;
|
||||
TypePChar VPC_DestStart = 0 ;
|
||||
TypeLength VL_MoveStart = 0 ;
|
||||
TypeLength VL_DestStart = 0 ;
|
||||
TypeLength VL_MemMoveSize= 0 ;
|
||||
|
||||
if(AL_Replace<=AL_Searched) // 메모리 증가 불필요
|
||||
{
|
||||
TypePChar VPC_MoveStart = 0 ;
|
||||
@ -177,75 +182,54 @@ namespace ZNsMain
|
||||
if(AL_Replace<=AL_Searched) // 메모리 증가 불필요*/
|
||||
|
||||
|
||||
ARR_SaveOut.resize(VL_NeedSize);
|
||||
/*======*/ VL_SearchedPre = this->size() ;
|
||||
/*======*/ VH_IterEasyID = AR_CPosList.ItTID() ;
|
||||
TypeLength VL_NowEleNo = VL_PosListSize ;
|
||||
TypeLength VL_DiffLength = AL_Replace-AL_Searched;
|
||||
|
||||
TypePChar VPC_OutStart = const_cast<char*>(ARR_SaveOut.data()) ;
|
||||
TypePChar VPC_CopyStart = 0 ;
|
||||
TypePChar VPC_DestStart = 0 ;
|
||||
TypeLength VL_CopyStart = 0 ;
|
||||
TypeLength VL_DestStart = 0 ;
|
||||
|
||||
TypeLength VL_MemCopySize= 0 ;
|
||||
TypePChar VPC_RepalcePos= 0 ;
|
||||
this->resize(VL_NeedSize); VPC_ThisStart = this->data();
|
||||
|
||||
__for1(TypeLength, i, VL_PosListSize)
|
||||
{
|
||||
VL_SearchedPos = AR_CPosList.ItD(VH_IterEasyID) ;
|
||||
VPC_CopyStart = VPC_ThisStart + VL_SearchedPre ;
|
||||
VL_DestStart = VL_SearchedPre +
|
||||
( AL_Replace-AL_Searched ) * (i-1) ;
|
||||
VPC_DestStart = VPC_OutStart + VL_DestStart ;
|
||||
VL_MemMoveSize = VL_SearchedPre - (VL_SearchedPos+AL_Searched);
|
||||
|
||||
if(VL_SearchedPos>VL_SearchedPre)
|
||||
if(VL_MemMoveSize>0)
|
||||
{
|
||||
VL_MemCopySize =
|
||||
VL_SearchedPos - VL_SearchedPre ;
|
||||
VPC_MoveStart = VPC_ThisStart + VL_SearchedPos + AL_Searched ;
|
||||
VPC_DestStart = VPC_ThisStart + VL_SearchedPos + AL_Searched + VL_DiffLength*VL_NowEleNo ;
|
||||
|
||||
::memcpy /*:::::::::::::::::::::::::::::::::::::::*/
|
||||
::memmove /*::::::::::::::::::::::::::::::::::::::::*/
|
||||
(
|
||||
VPC_DestStart, VPC_CopyStart, VL_MemCopySize
|
||||
VPC_DestStart, VPC_MoveStart, VL_MemMoveSize
|
||||
);
|
||||
/*::::::::::::::::::::::::::::::::::::::::::::::::*/
|
||||
/*::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
||||
}/*
|
||||
if(VL_SearchedPos>VL_SearchedPre)*/
|
||||
if(VL_MemMoveSize>0)*/
|
||||
|
||||
VL_SearchedPre = VL_SearchedPos + AL_Searched ;
|
||||
VL_DestStart = VL_SearchedPos +
|
||||
( AL_Replace-AL_Searched ) * (i-1) ;
|
||||
VPC_RepalcePos = VPC_OutStart + VL_DestStart ;
|
||||
VPC_DestStart = VPC_ThisStart + VL_SearchedPos + VL_DiffLength*(VL_PosListSize - i) ;
|
||||
|
||||
::memcpy(VPC_RepalcePos, APC_Replace, AL_Replace) ;
|
||||
::memcpy /*::::::::::::::::::::::::::::::::::::::::*/
|
||||
(
|
||||
VPC_DestStart, APC_Replace, AL_Replace
|
||||
);
|
||||
/*::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
||||
|
||||
AR_CPosList.ItNext(VH_IterEasyID);
|
||||
VL_SearchedPre = VL_SearchedPos; --VL_NowEleNo;
|
||||
|
||||
AR_CPosList.ItPrev(VH_IterEasyID);
|
||||
}/*
|
||||
__for1(TypeLength, i, VL_PosListSize)*/
|
||||
|
||||
|
||||
if(VL_SearchedPre<VL_ThisSize)
|
||||
{
|
||||
VL_DestStart = VL_DestStart + AL_Replace ;
|
||||
VPC_DestStart = VPC_OutStart + VL_DestStart ;
|
||||
VPC_CopyStart = VPC_ThisStart+ VL_SearchedPre;
|
||||
VL_MemCopySize = VL_ThisSize - VL_SearchedPre;
|
||||
|
||||
::memcpy /*:::::::::::::::::::::::::::::::::::::::*/
|
||||
(
|
||||
VPC_DestStart, VPC_CopyStart, VL_MemCopySize
|
||||
);
|
||||
/*::::::::::::::::::::::::::::::::::::::::::::::::*/
|
||||
}/*
|
||||
if(VL_SearchedPre<VL_ThisSize)*/
|
||||
|
||||
|
||||
return ARR_SaveOut;
|
||||
return *this;
|
||||
}/*
|
||||
template<typename TPosList> ZCStringStd& ReplaceToOutByPosList
|
||||
template<typename TPosList> ZCStringStd& ReplaceByPosList
|
||||
(
|
||||
TPosList& AR_CPosList ,
|
||||
TypeCPChar APC_Replace ,
|
||||
TypeLength AL_Replace ,
|
||||
TypeLength AL_Searched ,
|
||||
ZCStringStd& ARR_SaveOut
|
||||
TypeLength AL_Searched
|
||||
)
|
||||
############################################################*/
|
||||
|
||||
@ -267,12 +251,11 @@ namespace ZNsMain
|
||||
);
|
||||
/*////////////////////////////////////////////*/
|
||||
|
||||
ZCStringStd VO_CStringOut; return *this = ReplaceToOutByPosList
|
||||
return ReplaceByPosList /*::::::::::::::::::::::::::::*/
|
||||
(
|
||||
VO_CPosCList, APC_Replace, AL_Replace, AL_Search, RR(VO_CStringOut)
|
||||
VO_CPosCList, APC_Replace, AL_Replace, AL_Search
|
||||
);
|
||||
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
||||
|
||||
/*::::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
||||
}/*
|
||||
ZCStringStd& Replace /*######################################################
|
||||
(
|
||||
|
Reference in New Issue
Block a user