Skip to content

Commit ea735b6

Browse files
authored
インデックスの範囲チェック処理の重複を削減する為に、引数 nIndex の範囲チェックを行わない CStringRef::operator [] メソッドを追加 (#1964)
CStringRef::At メソッドの代わりに新規追加した CStringRef::operator [] メソッドを使用
1 parent 199fd72 commit ea735b6

File tree

6 files changed

+30
-29
lines changed

6 files changed

+30
-29
lines changed

sakura_core/cmd/CViewCommander_Edit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ void CViewCommander::DelCharForOverwrite( const wchar_t* pszInput, int nLen )
900900
nPos += CNativeW::GetSizeOfChar(line.GetPtr(), line.GetLength(), nPos);
901901
nDelLen = 1;
902902
if( nKetaDiff < 0 && nPos < line.GetLength() ){
903-
wchar_t c = line.At(nPos);
903+
wchar_t c = line[nPos];
904904
if( c != WCODE::TAB && !WCODE::IsLineDelimiter(c,
905905
GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
906906
nDelLen = 2;

sakura_core/doc/layout/CLayoutMgr_DoLayout.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static bool _GetKeywordLength(
4848
CLogicInt nWordBgn = nPos;
4949
CLogicInt nWordLen = CLogicInt(0);
5050
CLayoutInt nWordKetas = CLayoutInt(0);
51-
while(nPos<cLineStr.GetLength() && IS_KEYWORD_CHAR(cLineStr.At(nPos))){
51+
while(nPos<cLineStr.GetLength() && IS_KEYWORD_CHAR(cLineStr[nPos])){
5252
CLogicXInt nCharSize = CNativeW::GetSizeOfChar( cLineStr, nPos );
5353
CLayoutInt k = cLayoutMgr.GetLayoutXOfChar(cLineStr, nPos);
5454

@@ -209,8 +209,8 @@ void CLayoutMgr::_DoGyotoKinsoku(SLayoutWork* pWork, PF_OnLine pfOnLine)
209209

210210
if( _IsKinsokuPosHead( GetMaxLineLayout() - pWork->nPosX, nCharKetas1, nCharKetas2 )
211211
&& IsKinsokuHead( pWork->cLineStr.At( pWork->nPos + nCharSize ) )
212-
&& !IsKinsokuHead( pWork->cLineStr.At( pWork->nPos ) ) // 1字前が行頭禁則の対象でないこと
213-
&& !IsKinsokuKuto( pWork->cLineStr.At( pWork->nPos ) ) ) // 1字前が句読点ぶら下げの対象でないこと
212+
&& !IsKinsokuHead( pWork->cLineStr[ pWork->nPos ] ) // 1字前が行頭禁則の対象でないこと
213+
&& !IsKinsokuKuto( pWork->cLineStr[ pWork->nPos ] ) ) // 1字前が句読点ぶら下げの対象でないこと
214214
{
215215
pWork->nWordBgn = pWork->nPos;
216216
pWork->nWordLen = nCharSize + CNativeW::GetSizeOfChar( pWork->cLineStr, pWork->nPos + nCharSize );
@@ -233,7 +233,7 @@ void CLayoutMgr::_DoGyomatsuKinsoku(SLayoutWork* pWork, PF_OnLine pfOnLine)
233233
CLayoutXInt nCharKetas1 = GetLayoutXOfChar( pWork->cLineStr, pWork->nPos );
234234
CLayoutXInt nCharKetas2 = GetLayoutXOfChar( pWork->cLineStr, pWork->nPos + nCharSize );
235235

236-
if( _IsKinsokuPosTail( GetMaxLineLayout() - pWork->nPosX, nCharKetas1, nCharKetas2 ) && IsKinsokuTail( pWork->cLineStr.At( pWork->nPos ) ) )
236+
if( _IsKinsokuPosTail( GetMaxLineLayout() - pWork->nPosX, nCharKetas1, nCharKetas2 ) && IsKinsokuTail( pWork->cLineStr[ pWork->nPos ] ) )
237237
{
238238
pWork->nWordBgn = pWork->nPos;
239239
pWork->nWordLen = nCharSize;
@@ -305,7 +305,7 @@ void CLayoutMgr::_MakeOneLine(SLayoutWork* pWork, PF_OnLine pfOnLine)
305305
//@@@ 2002.09.22 YAZAKI
306306
color.CheckColorMODE( &pWork->pcColorStrategy, pWork->nPos, pWork->cLineStr );
307307

308-
if( pWork->cLineStr.At(pWork->nPos) == WCODE::TAB ){
308+
if( pWork->cLineStr[pWork->nPos] == WCODE::TAB ){
309309
if(_DoTab(pWork, pfOnLine)){
310310
continue;
311311
}

sakura_core/mem/CNativeW.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class CStringRef final{
4545
[[nodiscard]] int GetLength() const noexcept { return static_cast<int>(m_nDataLen); }
4646
[[nodiscard]] bool IsValid() const noexcept { return m_pData != nullptr; }
4747
[[nodiscard]] wchar_t At( size_t nIndex ) const noexcept;
48+
[[nodiscard]] wchar_t operator []( size_t nIndex ) const noexcept { return m_pData[nIndex]; }
4849

4950
private:
5051
const wchar_t* m_pData = nullptr;

sakura_core/view/colors/CColor_Comment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bool CColor_LineComment::EndColor(const CStringRef& cStr, int nPos)
5151
}
5252

5353
//改行
54-
if( WCODE::IsLineDelimiter(cStr.At(nPos), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
54+
if( WCODE::IsLineDelimiter(cStr[nPos], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
5555
return true;
5656
}
5757

sakura_core/view/colors/CColor_Heredoc.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,21 @@ bool CColor_Heredoc::BeginColor(const CStringRef& cStr, int nPos)
7878
const int length = cStr.GetLength();
7979
int nPosIdStart = nPos + 3;
8080
for(; nPosIdStart < length; nPosIdStart++ ){
81-
if(cStr.At(nPosIdStart) != L'\t' && cStr.At(nPosIdStart) != L' '){
81+
if(cStr[nPosIdStart] != L'\t' && cStr[nPosIdStart] != L' '){
8282
break;
8383
}
8484
}
8585
wchar_t quote = L'\0';
8686
if( !(nPosIdStart < length) ){
8787
return false;
8888
}
89-
if( cStr.At(nPosIdStart) == L'\'' || cStr.At(nPosIdStart) == L'"' ){
90-
quote = cStr.At(nPosIdStart);
89+
if (cStr[nPosIdStart] == L'\'' || cStr[nPosIdStart] == L'"') {
90+
quote = cStr[nPosIdStart];
9191
nPosIdStart++;
9292
}
9393
int i = nPosIdStart;
9494
for(; i < length; i++ ){
95-
if( !(WCODE::IsAZ(cStr.At(i)) || WCODE::Is09(cStr.At(i)) || cStr.At(i) == L'_') ){
95+
if( !(WCODE::IsAZ(cStr[i]) || WCODE::Is09(cStr[i]) || cStr[i] == L'_') ){
9696
break;
9797
}
9898
}
@@ -101,13 +101,13 @@ bool CColor_Heredoc::BeginColor(const CStringRef& cStr, int nPos)
101101
}
102102
const int k = i;
103103
if( quote != L'\0' ){
104-
if( i < length && cStr.At(i) == quote ){
104+
if( i < length && cStr[i] == quote ){
105105
i++;
106106
}else{
107107
return false;
108108
}
109109
}
110-
if( i < length && WCODE::IsLineDelimiter(cStr.At(i), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
110+
if( i < length && WCODE::IsLineDelimiter(cStr[i], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
111111
m_id = std::wstring(cStr.GetPtr()+nPosIdStart, k - nPosIdStart);
112112
m_pszId = m_id.c_str();
113113
m_nSize = m_id.size();
@@ -129,11 +129,11 @@ bool CColor_Heredoc::EndColor(const CStringRef& cStr, int nPos)
129129
return false;
130130
}else{
131131
int i = m_nSize;
132-
if( i + 1 < cStr.GetLength() && cStr.At(i) == L';' && WCODE::IsLineDelimiter(cStr.At(i+1), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
132+
if( i + 1 < cStr.GetLength() && cStr[i] == L';' && WCODE::IsLineDelimiter(cStr[i+1], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
133133
// ID;
134134
this->m_nCOMMENTEND = i;
135135
return false;
136-
}else if( m_nSize < cStr.GetLength() && WCODE::IsLineDelimiter(cStr.At(m_nSize), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
136+
}else if( m_nSize < cStr.GetLength() && WCODE::IsLineDelimiter(cStr[m_nSize], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
137137
// ID
138138
this->m_nCOMMENTEND = m_nSize;
139139
return false;

sakura_core/view/colors/CColor_Quote.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ bool CColor_Quote::IsCppRawString(const CStringRef& cStr, int nPos)
103103
// \b = ^|[\s!"#$%&'()=@{};:<>?,.*/\-\+\[\]\]
104104
wchar_t c1 = L' ';
105105
if( 2 <= nPos ){
106-
c1 = cStr.At(nPos-2);
106+
c1 = cStr[nPos-2];
107107
}
108108
wchar_t c2 = L' ';
109109
if( 3 <= nPos ){
110-
c2 = cStr.At(nPos-3);
110+
c2 = cStr[nPos-3];
111111
}
112112
const wchar_t* pszSep = L" \t!\"#$%&'()=@{};:<>?,.*/-+[]";
113113
if( (c1 == 'u' || c1 == 'U' || c1 == 'L') ){
@@ -117,7 +117,7 @@ bool CColor_Quote::IsCppRawString(const CStringRef& cStr, int nPos)
117117
}else if( c1 == '8' && c2 == 'u' ){
118118
wchar_t c3 = L'\0';
119119
if( 4 <= nPos ){
120-
c3 = cStr.At(nPos-4);
120+
c3 = cStr[nPos-4];
121121
}
122122
if( NULL != wcschr(pszSep, c3) ){
123123
return true;
@@ -142,7 +142,7 @@ bool CColor_Quote::BeginColor(const CStringRef& cStr, int nPos)
142142
case STRING_LITERAL_CPP:
143143
if( IsCppRawString(cStr, nPos) ){
144144
for( int i = nPos + 1; i < cStr.GetLength(); i++ ){
145-
if( cStr.At(i) == '(' ){
145+
if( cStr[i] == '(' ){
146146
if( nPos + 1 < i ){
147147
m_tag = L')';
148148
m_tag.append( cStr.GetPtr()+nPos+1, i - (nPos + 1) );
@@ -179,7 +179,7 @@ bool CColor_Quote::BeginColor(const CStringRef& cStr, int nPos)
179179
break;
180180
case STRING_LITERAL_PYTHON:
181181
if( nPos + 2 < cStr.GetLength()
182-
&& cStr.At(nPos+1) == m_cQuote && cStr.At(nPos+2) == m_cQuote ){
182+
&& cStr[nPos+1] == m_cQuote && cStr[nPos+2] == m_cQuote ){
183183
m_nCOMMENTEND = Match_QuoteStr( m_szQuote, 3, nPos + 3, cStr, true );
184184
m_nColorTypeIndex = 3;
185185
return true;
@@ -198,9 +198,9 @@ bool CColor_Quote::BeginColor(const CStringRef& cStr, int nPos)
198198
// 終了文字列がない場合は行末までを色分け
199199
if( m_pTypeData->m_bStringEndLine ){
200200
// 改行コードを除く
201-
if( 0 < cStr.GetLength() && WCODE::IsLineDelimiter(cStr.At(cStr.GetLength()-1), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
202-
if( 1 < cStr.GetLength() && cStr.At(cStr.GetLength()-2) == WCODE::CR
203-
&& cStr.At(cStr.GetLength()-1) == WCODE::LF ){
201+
if( 0 < cStr.GetLength() && WCODE::IsLineDelimiter(cStr[cStr.GetLength()-1], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
202+
if( 1 < cStr.GetLength() && cStr[cStr.GetLength()-2] == WCODE::CR
203+
&& cStr[cStr.GetLength()-1] == WCODE::LF ){
204204
m_nCOMMENTEND = cStr.GetLength() - 2;
205205
}else{
206206
m_nCOMMENTEND = cStr.GetLength() - 1;
@@ -256,29 +256,29 @@ int CColor_Quote::Match_Quote( wchar_t wcQuote, int nPos, const CStringRef& cLin
256256
nCharChars = (Int)t_max(CLogicInt(1), CNativeW::GetSizeOfChar( cLineStr.GetPtr(), cLineStr.GetLength(), i ));
257257
if( escapeType == STRING_LITERAL_CPP ){
258258
// エスケープ \"
259-
if( 1 == nCharChars && cLineStr.At(i) == L'\\' ){
259+
if( 1 == nCharChars && cLineStr[i] == L'\\' ){
260260
++i;
261-
if( i < cLineStr.GetLength() && WCODE::IsLineDelimiter(cLineStr.At(i), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
261+
if( i < cLineStr.GetLength() && WCODE::IsLineDelimiter(cLineStr[i], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
262262
if( pbEscapeEnd ){
263263
*pbEscapeEnd = true;
264264
}
265265
}
266266
}else
267-
if( 1 == nCharChars && cLineStr.At(i) == wcQuote ){
267+
if( 1 == nCharChars && cLineStr[i] == wcQuote ){
268268
return i + 1;
269269
}
270270
}else if( escapeType == STRING_LITERAL_PLSQL ){
271271
// エスケープ ""
272-
if( 1 == nCharChars && cLineStr.At(i) == wcQuote ){
273-
if( i + 1 < cLineStr.GetLength() && cLineStr.At(i + 1) == wcQuote ){
272+
if( 1 == nCharChars && cLineStr[i] == wcQuote ){
273+
if( i + 1 < cLineStr.GetLength() && cLineStr[i + 1] == wcQuote ){
274274
++i;
275275
}else{
276276
return i + 1;
277277
}
278278
}
279279
}else{
280280
// エスケープなし
281-
if( 1 == nCharChars && cLineStr.At(i) == wcQuote ){
281+
if( 1 == nCharChars && cLineStr[i] == wcQuote ){
282282
return i + 1;
283283
}
284284
}

0 commit comments

Comments
 (0)