Skip to content

Commit 0899264

Browse files
committed
Remove cch parameters for CharsAreEqual and CaseSensitiveComputeHashCch
Renamed CaseSensitiveComputeHashCch to CaseSensitiveComputeHash. Fixed-up utf8 test collateral a little bit.
1 parent 858e654 commit 0899264

9 files changed

Lines changed: 37 additions & 35 deletions

File tree

lib/Common/Codex/Utf8Codex.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,15 @@ namespace utf8
437437
return DecodeUnitsIntoAndNullTerminate(buffer, pbUtf8, pbEnd, options);
438438
}
439439

440-
bool CharsAreEqual(__in_ecount(cch) LPCOLESTR pch, LPCUTF8 bch, LPCUTF8 end, size_t cch, DecodeOptions options)
440+
bool CharsAreEqual(LPCOLESTR pch, LPCUTF8 bch, LPCUTF8 end, DecodeOptions options)
441441
{
442442
DecodeOptions localOptions = options;
443-
while (cch-- > 0)
443+
while (bch < end)
444444
{
445445
if (*pch++ != utf8::Decode(bch, end, localOptions))
446+
{
446447
return false;
448+
}
447449
}
448450
return true;
449451
}

lib/Common/Codex/Utf8Codex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ namespace utf8
307307
size_t EncodeTrueUtf8IntoAndNullTerminate(__out_ecount(cch * 3 + 1) utf8char_t *buffer, __in_ecount(cch) const char16 *source, charcount_t cch);
308308

309309
// Returns true if the pch refers to a UTF-16LE encoding of the given UTF-8 encoding bch.
310-
bool CharsAreEqual(__in_ecount(cch) LPCOLESTR pch, LPCUTF8 bch, LPCUTF8 end, size_t cch, DecodeOptions options = doDefault);
310+
bool CharsAreEqual(LPCOLESTR pch, LPCUTF8 bch, LPCUTF8 end, DecodeOptions options = doDefault);
311311

312312
// Convert the character index into a byte index.
313313
size_t CharacterIndexToByteIndex(__in_ecount(cbLength) LPCUTF8 pch, size_t cbLength, const charcount_t cchIndex, size_t cbStartIndex, charcount_t cchStartIndex, DecodeOptions options = doDefault);

lib/Parser/Hash.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ IdentPtr HashTbl::PidHashNameLen(CharType const * prgch, CharType const * end, u
222222
// NOTE: We use case sensitive hash during compilation, but the runtime
223223
// uses case insensitive hashing so it can do case insensitive lookups.
224224

225-
uint32 luHash = CaseSensitiveComputeHashCch(prgch, end, cch);
225+
uint32 luHash = CaseSensitiveComputeHash(prgch, end);
226226
return PidHashNameLenWithHash(prgch, end, cch, luHash);
227227
}
228228
template IdentPtr HashTbl::PidHashNameLen<utf8char_t>(utf8char_t const * prgch, utf8char_t const * end, uint32 cch);
@@ -244,7 +244,7 @@ IdentPtr HashTbl::PidHashNameLenWithHash(_In_reads_(cch) CharType const * prgch,
244244
{
245245
Assert(cch >= 0);
246246
AssertArrMemR(prgch, cch);
247-
Assert(luHash == CaseSensitiveComputeHashCch(prgch, end, cch));
247+
Assert(luHash == CaseSensitiveComputeHash(prgch, end));
248248

249249
IdentPtr * ppid;
250250
IdentPtr pid;
@@ -352,7 +352,7 @@ IdentPtr HashTbl::FindExistingPid(
352352
for (bucketCount = 0; nullptr != (pid = *ppid); ppid = &pid->m_pidNext, bucketCount++)
353353
{
354354
if (pid->m_luHash == luHash && (int)pid->m_cch == cch &&
355-
HashTbl::CharsAreEqual(pid->m_sz, prgch, end, cch))
355+
HashTbl::CharsAreEqual(pid->m_sz, prgch, end))
356356
{
357357
return pid;
358358
}
@@ -394,12 +394,12 @@ template IdentPtr HashTbl::FindExistingPid<char16>(
394394

395395
bool HashTbl::Contains(_In_reads_(cch) LPCOLESTR prgch, int32 cch)
396396
{
397-
uint32 luHash = CaseSensitiveComputeHashCch(prgch, prgch + cch, cch);
397+
uint32 luHash = CaseSensitiveComputeHash(prgch, prgch + cch);
398398

399399
for (auto pid = m_prgpidName[luHash & m_luMask]; pid; pid = pid->m_pidNext)
400400
{
401401
if (pid->m_luHash == luHash && (int)pid->m_cch == cch &&
402-
HashTbl::CharsAreEqual(pid->m_sz, prgch + cch, prgch, cch))
402+
HashTbl::CharsAreEqual(pid->m_sz, prgch + cch, prgch))
403403
{
404404
return true;
405405
}
@@ -419,7 +419,7 @@ bool HashTbl::Contains(_In_reads_(cch) LPCOLESTR prgch, int32 cch)
419419
// This method is used during colorizing when scanner isn't interested in storing the actual id and does not care about conversion of escape sequences
420420
tokens HashTbl::TkFromNameLenColor(_In_reads_(cch) LPCOLESTR prgch, uint32 cch)
421421
{
422-
uint32 luHash = CaseSensitiveComputeHashCch(prgch, prgch + cch, cch);
422+
uint32 luHash = CaseSensitiveComputeHash(prgch, prgch + cch);
423423

424424
// look for a keyword
425425
#include "kwds_sw.h"
@@ -446,7 +446,7 @@ tokens HashTbl::TkFromNameLenColor(_In_reads_(cch) LPCOLESTR prgch, uint32 cch)
446446
// This method is used during colorizing when scanner isn't interested in storing the actual id and does not care about conversion of escape sequences
447447
tokens HashTbl::TkFromNameLen(_In_reads_(cch) LPCOLESTR prgch, uint32 cch, bool isStrictMode)
448448
{
449-
uint32 luHash = CaseSensitiveComputeHashCch(prgch, prgch + cch, cch);
449+
uint32 luHash = CaseSensitiveComputeHash(prgch, prgch + cch);
450450

451451
// look for a keyword
452452
#include "kwds_sw.h"

lib/Parser/Hash.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ typedef StaticSymLen<0> StaticSym;
2121
/***************************************************************************
2222
Hashing functions. Definitions in core\hashfunc.cpp.
2323
***************************************************************************/
24-
ULONG CaseSensitiveComputeHashCch(LPCOLESTR prgch, LPCOLESTR end, int32 cch);
25-
ULONG CaseSensitiveComputeHashCch(LPCUTF8 prgch, LPCUTF8 end, int32 cch);
24+
ULONG CaseSensitiveComputeHash(LPCOLESTR prgch, LPCOLESTR end);
25+
ULONG CaseSensitiveComputeHash(LPCUTF8 prgch, LPCUTF8 end);
2626
ULONG CaseInsensitiveComputeHash(LPCOLESTR posz);
2727

2828
enum
@@ -407,22 +407,22 @@ class HashTbl
407407
uint CountAndVerifyItems(IdentPtr *buckets, uint bucketCount, uint mask);
408408
#endif
409409

410-
static bool CharsAreEqual(__in_z LPCOLESTR psz1, __in_ecount(cch2) LPCOLESTR psz2, LPCOLESTR psz2end, int32 cch2)
410+
static bool CharsAreEqual(__in_z LPCOLESTR psz1, __in_ecount(psz2end - psz2) LPCOLESTR psz2, LPCOLESTR psz2end)
411411
{
412-
Unused(psz2end);
413-
return memcmp(psz1, psz2, cch2 * sizeof(OLECHAR)) == 0;
412+
return memcmp(psz1, psz2, (psz2end - psz2) * sizeof(OLECHAR)) == 0;
414413
}
415-
static bool CharsAreEqual(__in_z LPCOLESTR psz1, LPCUTF8 psz2, LPCUTF8 psz2end, int32 cch2)
414+
static bool CharsAreEqual(__in_z LPCOLESTR psz1, LPCUTF8 psz2, LPCUTF8 psz2end)
416415
{
417-
return utf8::CharsAreEqual(psz1, psz2, psz2end, cch2, utf8::doAllowThreeByteSurrogates);
416+
return utf8::CharsAreEqual(psz1, psz2, psz2end, utf8::doAllowThreeByteSurrogates);
418417
}
419-
static bool CharsAreEqual(__in_z LPCOLESTR psz1, __in_ecount(cch2) char const * psz2, char const * psz2end, int32 cch2)
418+
static bool CharsAreEqual(__in_z LPCOLESTR psz1, __in_ecount(psz2end - psz2) char const * psz2, char const * psz2end)
420419
{
421-
Unused(psz2end);
422-
while (cch2-- > 0)
420+
while (psz2 < psz2end)
423421
{
424422
if (*psz1++ != *psz2++)
423+
{
425424
return false;
425+
}
426426
}
427427
return true;
428428
}

lib/Parser/HashFunc.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@
1616
* of the hash function so things don't go out of sync.
1717
*/
1818

19-
ULONG CaseSensitiveComputeHashCch(LPCOLESTR prgch, LPCOLESTR end, int32 cch)
19+
ULONG CaseSensitiveComputeHash(LPCOLESTR prgch, LPCOLESTR end)
2020
{
21-
Unused(end);
2221
ULONG luHash = 0;
2322

24-
while (cch-- > 0)
23+
while (prgch < end)
24+
{
2525
luHash = 17 * luHash + *(char16 *)prgch++;
26+
}
2627
return luHash;
2728
}
2829

29-
ULONG CaseSensitiveComputeHashCch(LPCUTF8 prgch, LPCUTF8 end, int32 cch)
30+
ULONG CaseSensitiveComputeHash(LPCUTF8 prgch, LPCUTF8 end)
3031
{
3132
utf8::DecodeOptions options = utf8::doAllowThreeByteSurrogates;
3233
ULONG luHash = 0;
3334

34-
while (cch-- > 0)
35+
while (prgch < end)
3536
{
3637
luHash = 17 * luHash + utf8::Decode(prgch, end, options);
3738
}
3839
return luHash;
3940
}
4041

41-
ULONG CaseSensitiveComputeHashCch(char const * prgch, char const * end, int32 cch)
42+
ULONG CaseSensitiveComputeHash(char const * prgch, char const * end)
4243
{
43-
Unused(end);
4444
ULONG luHash = 0;
4545

46-
while (cch-- > 0)
46+
while (prgch < end)
4747
{
4848
Assert(utf8::IsStartByte(*prgch) && !utf8::IsLeadByte(*prgch));
4949
luHash = 17 * luHash + *prgch++;

test/utf8/rlexe.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,22 @@
1010
<test>
1111
<default>
1212
<files>unicode_digit_as_identifier_should_work.js</files>
13-
<baseline />
1413
<tags>exclude_serialized,bugfix</tags>
1514
</default>
1615
</test>
1716
<test>
1817
<default>
1918
<files>surrogatepair.js</files>
20-
<baseline />
2119
</default>
2220
</test>
2321
<test>
2422
<default>
2523
<files>bugGH2386.js</files>
26-
<baseline />
2724
</default>
2825
</test>
2926
<test>
3027
<default>
3128
<files>unicode_sequence_serialized.js</files>
32-
<baseline />
3329
<compile-flags>-forceserialized -oopjit-</compile-flags>
3430
</default>
3531
</test>

test/utf8/surrogatepair.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var y = "function () { 'চ𐌲𐌿𐍄𐌹𐍃𐌺নির্বাচিত
99
var x = function () { 'চ𐌲𐌿𐍄𐌹𐍃𐌺নির্বাচিত নিবন্ধ।' ;WScript.Echo('hello'); }
1010

1111
// 2 bytes
12-
var y2 = "function () { ' kugu' ;WScript.Echo('hello'); }"
13-
var x2 = function () { ' kugu' ;WScript.Echo('hello'); }
12+
var y2 = "function () { 'üç kuğu' ;WScript.Echo('hello'); }"
13+
var x2 = function () { 'üç kuğu' ;WScript.Echo('hello'); }
1414

1515
WScript.Echo((x.toString() === y && x2.toString() === y2) ? "PASS" : "FAIL");

test/utf8/unicode_digit_as_identifier_should_work.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
44
//-------------------------------------------------------------------------------------------------------
55

6-
var a᠐᠙ᠠᡷᢀᡨᡩᡪᡫ=20;
6+
var a᠐᠙ᠠᡷᢀᡨᡩᡪᡫ=20;
7+
8+
print('pass');

test/utf8/unicode_sequence_serialized.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
(function () {
77
/()/ ;
88
})();
9+
10+
print('pass');

0 commit comments

Comments
 (0)