summaryrefslogtreecommitdiff
path: root/src/classlibnative/bcltype
diff options
context:
space:
mode:
authorBruce Bowyer-Smyth <bbowyersmyth@live.com.au>2017-08-09 03:25:31 +1000
committerJan Kotas <jkotas@microsoft.com>2017-08-08 10:25:31 -0700
commit9a405f2f61e477fc8964ded0788d4c20a1abd8da (patch)
tree247b5b786688ef357b58adc0238cca9624e4e2b7 /src/classlibnative/bcltype
parent8f009827812cf8aeeadf4c8a3c5bfe113db75d24 (diff)
downloadcoreclr-9a405f2f61e477fc8964ded0788d4c20a1abd8da.tar.gz
coreclr-9a405f2f61e477fc8964ded0788d4c20a1abd8da.tar.bz2
coreclr-9a405f2f61e477fc8964ded0788d4c20a1abd8da.zip
Improve performance of string.IndexOfAny for 2 & 3 char searches (#13219)
Diffstat (limited to 'src/classlibnative/bcltype')
-rw-r--r--src/classlibnative/bcltype/stringnative.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/classlibnative/bcltype/stringnative.cpp b/src/classlibnative/bcltype/stringnative.cpp
index af6593a6be..1a92e04815 100644
--- a/src/classlibnative/bcltype/stringnative.cpp
+++ b/src/classlibnative/bcltype/stringnative.cpp
@@ -327,8 +327,6 @@ FCIMPL4(INT32, COMString::IndexOfCharArray, StringObject* thisRef, CHARArray* va
if (thisRef == NULL)
FCThrow(kNullReferenceException);
- if (valueRef == NULL)
- FCThrowArgumentNull(W("anyOf"));
WCHAR *thisChars;
WCHAR *valueChars;
@@ -337,14 +335,6 @@ FCIMPL4(INT32, COMString::IndexOfCharArray, StringObject* thisRef, CHARArray* va
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;
valueLength = valueRef->GetNumComponents();
@@ -494,19 +484,31 @@ void InitializeProbabilisticMap(int* charMap, __in_ecount(length) const WCHAR* c
_ASSERTE(charArray != NULL);
_ASSERTE(length >= 0);
+ bool hasAscii = false;
+
for(int i = 0; i < length; ++i) {
int hi,lo;
- WCHAR c = charArray[i];
+ int c = charArray[i];
- hi = (c >> 8) & 0xFF;
lo = c & 0xFF;
+ hi = (c >> 8) & 0xFF;
int* value = &charMap[lo & PROBABILISTICMAP_BLOCK_INDEX_MASK];
SetBit(value, lo >> PROBABILISTICMAP_BLOCK_INDEX_SHIFT);
- value = &charMap[hi & PROBABILISTICMAP_BLOCK_INDEX_MASK];
- SetBit(value, hi >> 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;
}
}