@@ -209,31 +209,42 @@ IdentPtr HashTbl::PidFromTk(tokens token)
209209 {
210210 StaticSym const * sym = s_reservedWordInfo[token].sym ;
211211 Assert (sym != nullptr );
212- rpid = this ->PidHashNameLenWithHash (sym->sz , sym->cch , sym->luHash );
212+ rpid = this ->PidHashNameLenWithHash (sym->sz , sym->sz + sym-> cch , sym-> cch , sym->luHash );
213213 rpid->SetTk (token, s_reservedWordInfo[token].grfid );
214214 m_rpid[token] = rpid;
215215 }
216216 return rpid;
217217}
218218
219219template <typename CharType>
220- IdentPtr HashTbl::PidHashNameLen (CharType const * prgch, uint32 cch)
220+ IdentPtr HashTbl::PidHashNameLen (CharType const * prgch, CharType const * end, uint32 cch)
221221{
222222 // NOTE: We use case sensitive hash during compilation, but the runtime
223223 // uses case insensitive hashing so it can do case insensitive lookups.
224- uint32 luHash = CaseSensitiveComputeHashCch (prgch, cch);
225- return PidHashNameLenWithHash (prgch, cch, luHash);
224+
225+ uint32 luHash = CaseSensitiveComputeHash (prgch, end);
226+ return PidHashNameLenWithHash (prgch, end, cch, luHash);
227+ }
228+ template IdentPtr HashTbl::PidHashNameLen<utf8char_t >(utf8char_t const * prgch, utf8char_t const * end, uint32 cch);
229+ template IdentPtr HashTbl::PidHashNameLen<char >(char const * prgch, char const * end, uint32 cch);
230+ template IdentPtr HashTbl::PidHashNameLen<char16>(char16 const * prgch, char16 const * end, uint32 cch);
231+
232+ template <typename CharType>
233+ IdentPtr HashTbl::PidHashNameLen (CharType const * prgch, uint32 cch)
234+ {
235+ Assert (sizeof (CharType) == 2 );
236+ return PidHashNameLen (prgch, prgch + cch, cch);
226237};
227238template IdentPtr HashTbl::PidHashNameLen<utf8char_t >(utf8char_t const * prgch, uint32 cch);
228239template IdentPtr HashTbl::PidHashNameLen<char >(char const * prgch, uint32 cch);
229240template IdentPtr HashTbl::PidHashNameLen<char16>(char16 const * prgch, uint32 cch);
230241
231242template <typename CharType>
232- IdentPtr HashTbl::PidHashNameLenWithHash (_In_reads_(cch) CharType const * prgch, int32 cch, uint32 luHash)
243+ IdentPtr HashTbl::PidHashNameLenWithHash (_In_reads_(cch) CharType const * prgch, CharType const * end, int32 cch, uint32 luHash)
233244{
234245 Assert (cch >= 0 );
235246 AssertArrMemR (prgch, cch);
236- Assert (luHash == CaseSensitiveComputeHashCch (prgch, cch ));
247+ Assert (luHash == CaseSensitiveComputeHash (prgch, end ));
237248
238249 IdentPtr * ppid;
239250 IdentPtr pid;
@@ -245,7 +256,7 @@ IdentPtr HashTbl::PidHashNameLenWithHash(_In_reads_(cch) CharType const * prgch,
245256 int depth = 0 ;
246257#endif
247258
248- pid = this ->FindExistingPid (prgch, cch, luHash, &ppid, &bucketCount
259+ pid = this ->FindExistingPid (prgch, end, cch, luHash, &ppid, &bucketCount
249260#if PROFILE_DICTIONARY
250261 , depth
251262#endif
@@ -313,14 +324,15 @@ IdentPtr HashTbl::PidHashNameLenWithHash(_In_reads_(cch) CharType const * prgch,
313324 pid->m_propertyId = Js::Constants::NoProperty;
314325 pid->assignmentState = NotAssigned;
315326
316- HashTbl::CopyString (pid->m_sz , prgch, cch );
327+ HashTbl::CopyString (pid->m_sz , prgch, end );
317328
318329 return pid;
319330}
320331
321332template <typename CharType>
322333IdentPtr HashTbl::FindExistingPid (
323334 CharType const * prgch,
335+ CharType const * end,
324336 int32 cch,
325337 uint32 luHash,
326338 IdentPtr **pppInsert,
@@ -340,7 +352,7 @@ IdentPtr HashTbl::FindExistingPid(
340352 for (bucketCount = 0 ; nullptr != (pid = *ppid); ppid = &pid->m_pidNext , bucketCount++)
341353 {
342354 if (pid->m_luHash == luHash && (int )pid->m_cch == cch &&
343- HashTbl::CharsAreEqual (pid->m_sz , prgch, cch ))
355+ HashTbl::CharsAreEqual (pid->m_sz , prgch, end ))
344356 {
345357 return pid;
346358 }
@@ -362,32 +374,32 @@ IdentPtr HashTbl::FindExistingPid(
362374}
363375
364376template IdentPtr HashTbl::FindExistingPid<utf8char_t >(
365- utf8char_t const * prgch, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
377+ utf8char_t const * prgch, utf8char_t const * end, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
366378#if PROFILE_DICTIONARY
367379 , int & depth
368380#endif
369381 );
370382template IdentPtr HashTbl::FindExistingPid<char >(
371- char const * prgch, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
383+ char const * prgch, char const * end, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
372384#if PROFILE_DICTIONARY
373385 , int & depth
374386#endif
375387 );
376388template IdentPtr HashTbl::FindExistingPid<char16>(
377- char16 const * prgch, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
389+ char16 const * prgch, char16 const * end, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
378390#if PROFILE_DICTIONARY
379391 , int & depth
380392#endif
381393 );
382394
383395bool HashTbl::Contains (_In_reads_(cch) LPCOLESTR prgch, int32 cch)
384396{
385- uint32 luHash = CaseSensitiveComputeHashCch (prgch, cch);
397+ uint32 luHash = CaseSensitiveComputeHash (prgch, prgch + cch);
386398
387399 for (auto pid = m_prgpidName[luHash & m_luMask]; pid; pid = pid->m_pidNext )
388400 {
389401 if (pid->m_luHash == luHash && (int )pid->m_cch == cch &&
390- HashTbl::CharsAreEqual (pid->m_sz , prgch, cch))
402+ HashTbl::CharsAreEqual (pid->m_sz , prgch + cch, prgch ))
391403 {
392404 return true ;
393405 }
@@ -407,7 +419,7 @@ bool HashTbl::Contains(_In_reads_(cch) LPCOLESTR prgch, int32 cch)
407419// 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
408420tokens HashTbl::TkFromNameLenColor (_In_reads_(cch) LPCOLESTR prgch, uint32 cch)
409421{
410- uint32 luHash = CaseSensitiveComputeHashCch (prgch, cch);
422+ uint32 luHash = CaseSensitiveComputeHash (prgch, prgch + cch);
411423
412424 // look for a keyword
413425#include " kwds_sw.h"
@@ -434,7 +446,7 @@ tokens HashTbl::TkFromNameLenColor(_In_reads_(cch) LPCOLESTR prgch, uint32 cch)
434446// 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
435447tokens HashTbl::TkFromNameLen (_In_reads_(cch) LPCOLESTR prgch, uint32 cch, bool isStrictMode)
436448{
437- uint32 luHash = CaseSensitiveComputeHashCch (prgch, cch);
449+ uint32 luHash = CaseSensitiveComputeHash (prgch, prgch + cch);
438450
439451 // look for a keyword
440452#include " kwds_sw.h"
0 commit comments