Optimize FileReadByte/FileReadWord

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6400 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2013-07-28 14:46:24 +00:00
parent d387a32658
commit 55738e1385
2 changed files with 7 additions and 8 deletions

View file

@ -1419,14 +1419,14 @@ static int NSISCALL ExecuteEntry(entry *entry_)
{
TCHAR c;
#ifdef _UNICODE
c=0; // Make sure high byte is 0 for FileReadByte
if (which==EW_FGETS && !parm3)
if (which==EW_FGETS)
{
char tmpc[2];
DWORD mbtwcflags=MB_ERR_INVALID_CHARS, cbio;
if (!ReadFile(h,tmpc,2,&cbio,NULL) || !cbio) break;
if (!ReadFile(h,tmpc,2-parm3,&cbio,NULL) || !cbio) break;
ungetseek=cbio;
for(;;) // Try to parse as DBCS first, if that fails try again as a single byte
c = (unsigned char) tmpc[0]; // FileReadByte
if (!parm3) for(;;) // Try to parse as DBCS first, if that fails try again as a single byte
{
// BUGBUG: Limited to UCS-2/BMP, surrogate pairs are not supported.
if (MultiByteToWideChar(CP_ACP,mbtwcflags,tmpc,cbio,&c,1)) break;
@ -1438,9 +1438,8 @@ static int NSISCALL ExecuteEntry(entry *entry_)
else
#endif
{
// Read 1 TCHAR (FileReadUTF16LE and (Ansi)FileRead) or
// parm3 bytes (FileReadByte and (Unicode)FileReadWord)
if (!myReadFile(h,&c,!parm3 ? sizeof(TCHAR) : sizeof(TCHAR) > 1 ? parm3 : 1)) break;
// Read 1 TCHAR (FileReadUTF16LE, (Ansi)FileRead, FileReadWord)
if (!myReadFile(h,&c,sizeof(TCHAR))) break;
}
if (parm3)
{

View file

@ -5872,7 +5872,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
ent.offsets[0]=GetUserVarIndex(line, 1); // file handle
ent.offsets[1]=GetUserVarIndex(line, 2); // output string
ent.offsets[2]=add_asciistring(_T("1"));
ent.offsets[3]=2;
ent.offsets[3]=1;
if (ent.offsets[0]<0 || ent.offsets[1]<0) PRINTHELP()
SCRIPT_MSG(_T("FileReadWord: %s->%s\n"),line.gettoken_str(1),line.gettoken_str(2));
return add_entry(&ent);