Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 0 additions & 93 deletions src/classlibnative/bcltype/stringnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,49 +342,6 @@ FCIMPL5(INT32, COMString::CompareOrdinalEx, StringObject* strA, INT32 indexA, St
}
FCIMPLEND

/*=================================IndexOfChar==================================
**Action:
**Returns:
**Arguments:
**Exceptions:
==============================================================================*/

FCIMPL4 (INT32, COMString::IndexOfChar, StringObject* thisRef, CLR_CHAR value, INT32 startIndex, INT32 count )
{
FCALL_CONTRACT;

VALIDATEOBJECT(thisRef);
if (thisRef==NULL)
FCThrow(kNullReferenceException);

WCHAR *thisChars;
int thisLength;

thisRef->RefInterpretGetStringValuesDangerousForGC(&thisChars, &thisLength);

if (startIndex < 0 || startIndex > thisLength) {
FCThrowArgumentOutOfRange(W("startIndex"), W("ArgumentOutOfRange_Index"));
}

if (count < 0 || count > thisLength - startIndex) {
FCThrowArgumentOutOfRange(W("count"), W("ArgumentOutOfRange_Count"));
}

int endIndex = startIndex + count;
for (int i=startIndex; i<endIndex; i++)
{
if (thisChars[i]==((WCHAR)value))
{
FC_GC_POLL_RET();
return i;
}
}

FC_GC_POLL_RET();
return -1;
}
FCIMPLEND

/*===============================IndexOfCharArray===============================
**Action:
**Returns:
Expand Down Expand Up @@ -442,56 +399,6 @@ FCIMPL4(INT32, COMString::IndexOfCharArray, StringObject* thisRef, CHARArray* va
}
FCIMPLEND


/*===============================LastIndexOfChar================================
**Action:
**Returns:
**Arguments:
**Exceptions:
==============================================================================*/

FCIMPL4(INT32, COMString::LastIndexOfChar, StringObject* thisRef, CLR_CHAR value, INT32 startIndex, INT32 count )
{
FCALL_CONTRACT;

VALIDATEOBJECT(thisRef);
WCHAR *thisChars;
int thisLength;

if (thisRef==NULL) {
FCThrow(kNullReferenceException);
}

thisRef->RefInterpretGetStringValuesDangerousForGC(&thisChars, &thisLength);

if (thisLength == 0) {
FC_GC_POLL_RET();
return -1;
}


if (startIndex<0 || startIndex>=thisLength) {
FCThrowArgumentOutOfRange(W("startIndex"), W("ArgumentOutOfRange_Index"));
}

if (count<0 || count - 1 > startIndex) {
FCThrowArgumentOutOfRange(W("count"), W("ArgumentOutOfRange_Count"));
}

int endIndex = startIndex - count + 1;

//We search [startIndex..EndIndex]
for (int i=startIndex; i>=endIndex; i--) {
if (thisChars[i]==((WCHAR)value)) {
FC_GC_POLL_RET();
return i;
}
}

FC_GC_POLL_RET();
return -1;
}
FCIMPLEND
/*=============================LastIndexOfCharArray=============================
**Action:
**Returns:
Expand Down
4 changes: 0 additions & 4 deletions src/classlibnative/bcltype/stringnative.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ class COMString {

static FCDECL5(INT32, CompareOrdinalEx, StringObject* strA, INT32 indexA, StringObject* strB, INT32 indexB, INT32 count);

static FCDECL4(INT32, IndexOfChar, StringObject* vThisRef, CLR_CHAR value, INT32 startIndex, INT32 count );

static FCDECL4(INT32, LastIndexOfChar, StringObject* thisRef, CLR_CHAR value, INT32 startIndex, INT32 count );

static FCDECL4(INT32, LastIndexOfCharArray, StringObject* thisRef, CHARArray* valueRef, INT32 startIndex, INT32 count );

static FCDECL4(INT32, IndexOfCharArray, StringObject* vThisRef, CHARArray* value, INT32 startIndex, INT32 count );
Expand Down
88 changes: 84 additions & 4 deletions src/mscorlib/src/System/String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2293,8 +2293,46 @@ public int IndexOf(char value, int startIndex) {

[Pure]
[System.Security.SecuritySafeCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern int IndexOf(char value, int startIndex, int count);
public unsafe int IndexOf(char value, int startIndex, int count) {
if (startIndex < 0 || startIndex > Length)
throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));

if (count < 0 || count > Length - startIndex)
throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));

fixed (char* pChars = &m_firstChar)
{
char* pCh = pChars + startIndex;

while (count >= 4)
{
if (*pCh == value) goto ReturnIndex;
if (*(pCh + 1) == value) goto ReturnIndex1;
if (*(pCh + 2) == value) goto ReturnIndex2;
if (*(pCh + 3) == value) goto ReturnIndex3;

count -= 4;
pCh += 4;
}

while (count > 0)
{
if (*pCh == value)
goto ReturnIndex;

count--;
pCh++;
}

return -1;

ReturnIndex3: pCh++;
ReturnIndex2: pCh++;
ReturnIndex1: pCh++;
ReturnIndex:
return (int)(pCh - pChars);
}
}

// Returns the index of the first occurrence of any specified character in the current instance.
// The search starts at startIndex and runs to startIndex + count -1.
Expand Down Expand Up @@ -2420,8 +2458,50 @@ public int LastIndexOf(char value, int startIndex){

[Pure]
[System.Security.SecuritySafeCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern int LastIndexOf(char value, int startIndex, int count);
public unsafe int LastIndexOf(char value, int startIndex, int count) {
if (Length == 0)
return -1;

if (startIndex < 0 || startIndex >= Length)
throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));

if (count < 0 || count - 1 > startIndex)
throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));

fixed (char* pChars = &m_firstChar)
{
char* pCh = pChars + startIndex;

//We search [startIndex..EndIndex]
while (count >= 4)
{
if (*pCh == value) goto ReturnIndex;
if (*(pCh - 1) == value) goto ReturnIndex1;
if (*(pCh - 2) == value) goto ReturnIndex2;
if (*(pCh - 3) == value) goto ReturnIndex3;

count -= 4;
pCh -= 4;
}

while (count > 0)
{
if (*pCh == value)
goto ReturnIndex;

count--;
pCh--;
}

return -1;

ReturnIndex3: pCh--;
ReturnIndex2: pCh--;
ReturnIndex1: pCh--;
ReturnIndex:
return (int)(pCh - pChars);
}
}

// Returns the index of the last occurrence of any specified character in the current instance.
// The search starts at startIndex and runs backwards to startIndex - count + 1.
Expand Down
2 changes: 0 additions & 2 deletions src/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ FCFuncStart(gStringFuncs)
FCIntrinsic("get_Chars", COMString::GetCharAt, CORINFO_INTRINSIC_StringGetChar)
FCFuncElement("IsAscii", COMString::IsAscii)
FCFuncElement("nativeCompareOrdinalEx", COMString::CompareOrdinalEx)
FCFuncElement("IndexOf", COMString::IndexOfChar)
FCFuncElement("IndexOfAny", COMString::IndexOfCharArray)
FCFuncElement("LastIndexOf", COMString::LastIndexOfChar)
FCFuncElement("LastIndexOfAny", COMString::LastIndexOfCharArray)
FCFuncElementSig("ReplaceInternal", &gsig_IM_Str_Str_RetStr, COMString::ReplaceString)
#ifdef FEATURE_COMINTEROP
Expand Down