summaryrefslogtreecommitdiff
path: root/src/classlibnative
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2017-10-04 08:39:18 -0700
committerJan Kotas <jkotas@microsoft.com>2017-10-04 13:19:03 -0700
commit238907f69662dda53dee0afd9848756a5bb790e9 (patch)
tree10cb7b880e777175d74e91027eaa177921a83e9e /src/classlibnative
parent2de0bce49beeaf1bc6fcedd006114f4c8df7566a (diff)
downloadcoreclr-238907f69662dda53dee0afd9848756a5bb790e9.tar.gz
coreclr-238907f69662dda53dee0afd9848756a5bb790e9.tar.bz2
coreclr-238907f69662dda53dee0afd9848756a5bb790e9.zip
Move String.Searching.cs to shared CoreLib partition (dotnet/corert#4673)
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'src/classlibnative')
-rw-r--r--src/classlibnative/bcltype/stringnative.cpp232
-rw-r--r--src/classlibnative/bcltype/stringnative.h4
2 files changed, 0 insertions, 236 deletions
diff --git a/src/classlibnative/bcltype/stringnative.cpp b/src/classlibnative/bcltype/stringnative.cpp
index 34fbf1eb34..dc9be01680 100644
--- a/src/classlibnative/bcltype/stringnative.cpp
+++ b/src/classlibnative/bcltype/stringnative.cpp
@@ -31,22 +31,6 @@
#pragma optimize("tgy", on)
#endif
-
-#define PROBABILISTICMAP_BLOCK_INDEX_MASK 0X7
-#define PROBABILISTICMAP_BLOCK_INDEX_SHIFT 0x3
-#define PROBABILISTICMAP_SIZE 0X8
-
-//
-//
-// FORWARD DECLARATIONS
-//
-//
-int ArrayContains(WCHAR searchChar, __in_ecount(length) const WCHAR *begin, int length);
-void InitializeProbabilisticMap(int* charMap, __in_ecount(length) const WCHAR* charArray, int length);
-bool ProbablyContains(const int* charMap, WCHAR searchChar);
-bool IsBitSet(int value, int bitPos);
-void SetBit(int* value, int bitPos);
-
//
//
// CONSTRUCTORS
@@ -295,116 +279,6 @@ FCIMPL6(INT32, COMString::CompareOrdinalEx, StringObject* strA, INT32 indexA, IN
}
FCIMPLEND
-/*===============================IndexOfCharArray===============================
-**Action:
-**Returns:
-**Arguments:
-**Exceptions:
-==============================================================================*/
-FCIMPL4(INT32, COMString::IndexOfCharArray, StringObject* thisRef, CHARArray* valueRef, INT32 startIndex, INT32 count )
-{
- FCALL_CONTRACT;
-
- VALIDATEOBJECT(thisRef);
- VALIDATEOBJECT(valueRef);
-
- if (thisRef == NULL)
- FCThrow(kNullReferenceException);
-
- WCHAR *thisChars;
- WCHAR *valueChars;
- int valueLength;
- int thisLength;
-
- thisRef->RefInterpretGetStringValuesDangerousForGC(&thisChars, &thisLength);
-
- int endIndex = startIndex + count;
-
- valueLength = valueRef->GetNumComponents();
- valueChars = (WCHAR *)valueRef->GetDataPtr();
-
- // use probabilistic map, see (code:InitializeProbabilisticMap)
- int charMap[PROBABILISTICMAP_SIZE] = {0};
-
- InitializeProbabilisticMap(charMap, valueChars, valueLength);
-
- for(int i = startIndex; i < endIndex; i++) {
- WCHAR thisChar = thisChars[i];
- if (ProbablyContains(charMap, thisChar))
- if (ArrayContains(thisChars[i], valueChars, valueLength) >= 0) {
- FC_GC_POLL_RET();
- return i;
- }
- }
-
- FC_GC_POLL_RET();
- return -1;
-}
-FCIMPLEND
-
-/*=============================LastIndexOfCharArray=============================
-**Action:
-**Returns:
-**Arguments:
-**Exceptions:
-==============================================================================*/
-
-FCIMPL4(INT32, COMString::LastIndexOfCharArray, StringObject* thisRef, CHARArray* valueRef, INT32 startIndex, INT32 count )
-{
- FCALL_CONTRACT;
-
- VALIDATEOBJECT(thisRef);
- VALIDATEOBJECT(valueRef);
- WCHAR *thisChars, *valueChars;
- int thisLength, valueLength;
-
- if (thisRef==NULL) {
- FCThrow(kNullReferenceException);
- }
-
- if (valueRef == NULL)
- FCThrowArgumentNull(W("anyOf"));
-
- thisRef->RefInterpretGetStringValuesDangerousForGC(&thisChars, &thisLength);
-
- if (thisLength == 0) {
- 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"));
- }
-
-
- valueLength = valueRef->GetNumComponents();
- valueChars = (WCHAR *)valueRef->GetDataPtr();
-
- int endIndex = startIndex - count + 1;
-
- // use probabilistic map, see (code:InitializeProbabilisticMap)
- int charMap[PROBABILISTICMAP_SIZE] = {0};
-
- InitializeProbabilisticMap(charMap, valueChars, valueLength);
-
- //We search [startIndex..EndIndex]
- for (int i=startIndex; i>=endIndex; i--) {
- WCHAR thisChar = thisChars[i];
- if (ProbablyContains(charMap, thisChar))
- if (ArrayContains(thisChars[i],valueChars, valueLength) >= 0) {
- FC_GC_POLL_RET();
- return i;
- }
- }
-
- FC_GC_POLL_RET();
- return -1;
-
-}
-FCIMPLEND
/*==================================GETCHARAT===================================
**Returns the character at position index. Thows IndexOutOfRangeException as
@@ -447,112 +321,6 @@ FCIMPL1(INT32, COMString::Length, StringObject* str) {
FCIMPLEND
-// HELPER METHODS
-//
-//
-// A probabilistic map is an optimization that is used in IndexOfAny/
-// LastIndexOfAny methods. The idea is to create a bit map of the characters we
-// are searching for and use this map as a "cheap" check to decide if the
-// current character in the string exists in the array of input characters.
-// There are 256 bits in the map, with each character mapped to 2 bits. Every
-// character is divided into 2 bytes, and then every byte is mapped to 1 bit.
-// The character map is an array of 8 integers acting as map blocks. The 3 lsb
-// in each byte in the character is used to index into this map to get the
-// right block, the value of the remaining 5 msb are used as the bit position
-// inside this block.
-void InitializeProbabilisticMap(int* charMap, __in_ecount(length) const WCHAR* charArray, int length) {
- LIMITED_METHOD_CONTRACT;
-
- _ASSERTE(charMap != NULL);
- _ASSERTE(charArray != NULL);
- _ASSERTE(length >= 0);
-
- bool hasAscii = false;
-
- for(int i = 0; i < length; ++i) {
- int hi,lo;
-
- int c = charArray[i];
-
- lo = c & 0xFF;
- hi = (c >> 8) & 0xFF;
-
- int* value = &charMap[lo & PROBABILISTICMAP_BLOCK_INDEX_MASK];
- SetBit(value, lo >> PROBABILISTICMAP_BLOCK_INDEX_SHIFT);
-
- if (hi > 0) {
- value = &charMap[hi & PROBABILISTICMAP_BLOCK_INDEX_MASK];
- SetBit(value, hi >> PROBABILISTICMAP_BLOCK_INDEX_SHIFT);
- }
- else {
- hasAscii = true;
- }
- }
-
- if (hasAscii) {
- // Common to search for ASCII symbols. Just the high value once.
- charMap[0] |= 1;
- }
-}
-
-// Use the probabilistic map to decide if the character value exists in the
-// map. When this method return false, we are certain the character doesn't
-// exist, however a true return means it *may* exist.
-inline bool ProbablyContains(const int* charMap, WCHAR searchValue) {
- LIMITED_METHOD_CONTRACT;
-
- int lo, hi;
-
- lo = searchValue & 0xFF;
- int value = charMap[lo & PROBABILISTICMAP_BLOCK_INDEX_MASK];
-
- if (IsBitSet(value, lo >> PROBABILISTICMAP_BLOCK_INDEX_SHIFT)) {
- hi = (searchValue >> 8) & 0xFF;
- value = charMap[hi & PROBABILISTICMAP_BLOCK_INDEX_MASK];
-
- return IsBitSet(value, hi >> PROBABILISTICMAP_BLOCK_INDEX_SHIFT);
- }
-
- return false;
-}
-
-inline void SetBit(int* value, int bitPos) {
- LIMITED_METHOD_CONTRACT;
-
- _ASSERTE(bitPos <= 31);
-
- *value |= (1 << bitPos);
-}
-
-inline bool IsBitSet(int value, int bitPos) {
- LIMITED_METHOD_CONTRACT;
-
- _ASSERTE(bitPos <= 31);
-
- return (value & (1 << bitPos)) != 0;
-}
-
-
-/*================================ArrayContains=================================
-**Action:
-**Returns:
-**Arguments:
-**Exceptions:
-==============================================================================*/
-int ArrayContains(WCHAR searchChar, __in_ecount(length) const WCHAR *begin, int length) {
- LIMITED_METHOD_CONTRACT;
- _ASSERTE(begin != NULL);
- _ASSERTE(length >= 0);
-
- for(int i = 0; i < length; i++) {
- if(begin[i] == searchChar) {
- return i;
- }
- }
- return -1;
-}
-
-
/*================================ReplaceString=================================
**Action:
**Returns:
diff --git a/src/classlibnative/bcltype/stringnative.h b/src/classlibnative/bcltype/stringnative.h
index a8409826c6..24326ed818 100644
--- a/src/classlibnative/bcltype/stringnative.h
+++ b/src/classlibnative/bcltype/stringnative.h
@@ -61,10 +61,6 @@ public:
static FCDECL6(INT32, CompareOrdinalEx, StringObject* strA, INT32 indexA, INT32 countA, StringObject* strB, INT32 indexB, INT32 countB);
- static FCDECL4(INT32, LastIndexOfCharArray, StringObject* thisRef, CHARArray* valueRef, INT32 startIndex, INT32 count );
-
- static FCDECL4(INT32, IndexOfCharArray, StringObject* vThisRef, CHARArray* value, INT32 startIndex, INT32 count );
-
static FCDECL2(FC_CHAR_RET, GetCharAt, StringObject* pThisRef, INT32 index);
static FCDECL1(INT32, Length, StringObject* pThisRef);