@@ -209,31 +209,39 @@ 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 = CaseSensitiveComputeHashCch (prgch, end, cch);
226+ return PidHashNameLenWithHash (prgch, end, cch, luHash);
227+ }
228+
229+ template <typename CharType>
230+ IdentPtr HashTbl::PidHashNameLen (CharType const * prgch, uint32 cch)
231+ {
232+ Assert (sizeof (CharType) == 2 );
233+ return PidHashNameLen (prgch, prgch + cch, cch);
226234};
227235template IdentPtr HashTbl::PidHashNameLen<utf8char_t >(utf8char_t const * prgch, uint32 cch);
228236template IdentPtr HashTbl::PidHashNameLen<char >(char const * prgch, uint32 cch);
229237template IdentPtr HashTbl::PidHashNameLen<char16>(char16 const * prgch, uint32 cch);
230238
231239template <typename CharType>
232- IdentPtr HashTbl::PidHashNameLenWithHash (_In_reads_(cch) CharType const * prgch, int32 cch, uint32 luHash)
240+ IdentPtr HashTbl::PidHashNameLenWithHash (_In_reads_(cch) CharType const * prgch, CharType const * end, int32 cch, uint32 luHash)
233241{
234242 Assert (cch >= 0 );
235243 AssertArrMemR (prgch, cch);
236- Assert (luHash == CaseSensitiveComputeHashCch (prgch, cch));
244+ Assert (luHash == CaseSensitiveComputeHashCch (prgch, end, cch));
237245
238246 IdentPtr * ppid;
239247 IdentPtr pid;
@@ -245,7 +253,7 @@ IdentPtr HashTbl::PidHashNameLenWithHash(_In_reads_(cch) CharType const * prgch,
245253 int depth = 0 ;
246254#endif
247255
248- pid = this ->FindExistingPid (prgch, cch, luHash, &ppid, &bucketCount
256+ pid = this ->FindExistingPid (prgch, end, cch, luHash, &ppid, &bucketCount
249257#if PROFILE_DICTIONARY
250258 , depth
251259#endif
@@ -313,14 +321,15 @@ IdentPtr HashTbl::PidHashNameLenWithHash(_In_reads_(cch) CharType const * prgch,
313321 pid->m_propertyId = Js::Constants::NoProperty;
314322 pid->assignmentState = NotAssigned;
315323
316- HashTbl::CopyString (pid->m_sz , prgch, cch);
324+ HashTbl::CopyString (pid->m_sz , prgch, end, cch);
317325
318326 return pid;
319327}
320328
321329template <typename CharType>
322330IdentPtr HashTbl::FindExistingPid (
323331 CharType const * prgch,
332+ CharType const * end,
324333 int32 cch,
325334 uint32 luHash,
326335 IdentPtr **pppInsert,
@@ -340,7 +349,7 @@ IdentPtr HashTbl::FindExistingPid(
340349 for (bucketCount = 0 ; nullptr != (pid = *ppid); ppid = &pid->m_pidNext , bucketCount++)
341350 {
342351 if (pid->m_luHash == luHash && (int )pid->m_cch == cch &&
343- HashTbl::CharsAreEqual (pid->m_sz , prgch, cch))
352+ HashTbl::CharsAreEqual (pid->m_sz , prgch, end, cch))
344353 {
345354 return pid;
346355 }
@@ -362,32 +371,32 @@ IdentPtr HashTbl::FindExistingPid(
362371}
363372
364373template IdentPtr HashTbl::FindExistingPid<utf8char_t >(
365- utf8char_t const * prgch, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
374+ utf8char_t const * prgch, utf8char_t const * end, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
366375#if PROFILE_DICTIONARY
367376 , int & depth
368377#endif
369378 );
370379template IdentPtr HashTbl::FindExistingPid<char >(
371- char const * prgch, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
380+ char const * prgch, char const * end, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
372381#if PROFILE_DICTIONARY
373382 , int & depth
374383#endif
375384 );
376385template IdentPtr HashTbl::FindExistingPid<char16>(
377- char16 const * prgch, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
386+ char16 const * prgch, char16 const * end, int32 cch, uint32 luHash, IdentPtr **pppInsert, int32 *pBucketCount
378387#if PROFILE_DICTIONARY
379388 , int & depth
380389#endif
381390 );
382391
383392bool HashTbl::Contains (_In_reads_(cch) LPCOLESTR prgch, int32 cch)
384393{
385- uint32 luHash = CaseSensitiveComputeHashCch (prgch, cch);
394+ uint32 luHash = CaseSensitiveComputeHashCch (prgch, prgch + cch, cch);
386395
387396 for (auto pid = m_prgpidName[luHash & m_luMask]; pid; pid = pid->m_pidNext )
388397 {
389398 if (pid->m_luHash == luHash && (int )pid->m_cch == cch &&
390- HashTbl::CharsAreEqual (pid->m_sz , prgch, cch))
399+ HashTbl::CharsAreEqual (pid->m_sz , prgch + cch, prgch , cch))
391400 {
392401 return true ;
393402 }
@@ -407,7 +416,7 @@ bool HashTbl::Contains(_In_reads_(cch) LPCOLESTR prgch, int32 cch)
407416// 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
408417tokens HashTbl::TkFromNameLenColor (_In_reads_(cch) LPCOLESTR prgch, uint32 cch)
409418{
410- uint32 luHash = CaseSensitiveComputeHashCch (prgch, cch);
419+ uint32 luHash = CaseSensitiveComputeHashCch (prgch, prgch + cch, cch);
411420
412421 // look for a keyword
413422#include " kwds_sw.h"
@@ -434,7 +443,7 @@ tokens HashTbl::TkFromNameLenColor(_In_reads_(cch) LPCOLESTR prgch, uint32 cch)
434443// 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
435444tokens HashTbl::TkFromNameLen (_In_reads_(cch) LPCOLESTR prgch, uint32 cch, bool isStrictMode)
436445{
437- uint32 luHash = CaseSensitiveComputeHashCch (prgch, cch);
446+ uint32 luHash = CaseSensitiveComputeHashCch (prgch, prgch + cch, cch);
438447
439448 // look for a keyword
440449#include " kwds_sw.h"
0 commit comments