mirror of
https://github.com/ptitSeb/Serious-Engine
synced 2024-11-22 02:20:25 +01:00
Performance fix Ecc
This commit is contained in:
parent
cfefaf581a
commit
9f50d3ef84
|
@ -241,7 +241,7 @@ enum ESStatus
|
||||||
/* Determine whether or not our target ES file is indeed valid input. */
|
/* Determine whether or not our target ES file is indeed valid input. */
|
||||||
ESStatus GetESStatus(char *filename)
|
ESStatus GetESStatus(char *filename)
|
||||||
{
|
{
|
||||||
ESStatus result = ESStatus::Good;
|
ESStatus result = ESStatus::Empty;
|
||||||
|
|
||||||
// Read a temporary buffer of the entire file contents
|
// Read a temporary buffer of the entire file contents
|
||||||
fseek(_fInput, 0, SEEK_END);
|
fseek(_fInput, 0, SEEK_END);
|
||||||
|
@ -251,72 +251,77 @@ ESStatus GetESStatus(char *filename)
|
||||||
fread(temporaryBuffer, length, 1, _fInput);
|
fread(temporaryBuffer, length, 1, _fInput);
|
||||||
fclose(_fInput);
|
fclose(_fInput);
|
||||||
|
|
||||||
// First, let's remove line comments
|
// Loop through each line
|
||||||
char *commentBegin = NULL;
|
char* currentSequence = strtok(temporaryBuffer, "\n");
|
||||||
while (commentBegin = strstr(temporaryBuffer, "//"))
|
|
||||||
|
// No newlines, but it might still be valid.
|
||||||
|
if (!currentSequence)
|
||||||
|
currentSequence = temporaryBuffer;
|
||||||
|
|
||||||
|
bool inBlockComment = false;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
size_t commentLength = length;
|
size_t sequenceLength = strlen(currentSequence);
|
||||||
|
|
||||||
char* lineEnding = strstr(commentBegin, "\n");
|
for (size_t iteration = 0; iteration < sequenceLength; iteration++)
|
||||||
if (lineEnding)
|
|
||||||
commentLength = (size_t)(lineEnding) - (size_t)commentBegin;
|
|
||||||
|
|
||||||
memset(commentBegin, 0x20, commentLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then block comments
|
|
||||||
commentBegin = NULL;
|
|
||||||
while (commentBegin = strstr(temporaryBuffer, "/*"))
|
|
||||||
{
|
|
||||||
size_t commentLength = length;
|
|
||||||
|
|
||||||
char* commentEnd = strstr(commentBegin, "*/");
|
|
||||||
if (commentEnd)
|
|
||||||
commentLength = (size_t)(commentEnd + 3) - (size_t)commentBegin;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
result = ESStatus::Error;
|
// If we're still in a block comment, find the closing */
|
||||||
break;
|
if (inBlockComment)
|
||||||
}
|
{
|
||||||
|
char* blockClosing = strstr(currentSequence, "*/");
|
||||||
memset(commentBegin, 0x20, commentLength);
|
if (!blockClosing)
|
||||||
}
|
break;
|
||||||
|
else
|
||||||
// If we return here, it was because of unbalanced block comments
|
{
|
||||||
if (result != ESStatus::Good)
|
inBlockComment = false;
|
||||||
{
|
iteration = ((size_t)blockClosing - (size_t)currentSequence) + 2;
|
||||||
free(temporaryBuffer);
|
}
|
||||||
return result;
|
}
|
||||||
}
|
|
||||||
|
// If we find a // sequence, simply skip this line
|
||||||
// Now we just loop through the buffer until we find something that's not 0x20 or \n
|
if (currentSequence[iteration] == '/' && currentSequence[iteration + 1] == '/')
|
||||||
result = ESStatus::Empty;
|
break;
|
||||||
for (size_t iteration = 0; iteration < length; iteration++)
|
|
||||||
if (temporaryBuffer[iteration] != 0x20 && temporaryBuffer[iteration] != '\n')
|
// If we find a /* on this line but not a closing */, skip this line
|
||||||
{
|
if (currentSequence[iteration] == '/' && currentSequence[iteration + 1] == '*')
|
||||||
size_t checkLength = length;
|
{
|
||||||
char* checkStart = &temporaryBuffer[iteration];
|
// Is there a closing */ on this line?
|
||||||
|
char* blockClosing = strstr(currentSequence, "*/");
|
||||||
char* lineEnding = strstr(checkStart, "\n");
|
|
||||||
if (lineEnding)
|
if (!blockClosing)
|
||||||
checkLength = (size_t)(lineEnding) - (size_t)checkStart;
|
{
|
||||||
|
inBlockComment = true;
|
||||||
// Loop through and use isdigit to check all the digits
|
break;
|
||||||
checkStart[checkLength + 1] = 0x00;
|
}
|
||||||
|
else
|
||||||
for (int digit = 0; digit < strlen(checkStart); digit++)
|
{
|
||||||
if (checkStart[digit] != 0x20 && checkStart[digit] != '\n' && isdigit(checkStart[digit]))
|
iteration = ((size_t)blockClosing - (size_t)currentSequence) + 2;
|
||||||
result = ESStatus::Good;
|
inBlockComment = false;
|
||||||
else if (checkStart[digit] != 0x20 && checkStart[digit] != '\n')
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iteration >= sequenceLength)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// If we got to this point, we should be able to read only a number on this line
|
||||||
|
for (size_t checkIteration = 0; checkIteration < sequenceLength; checkIteration++)
|
||||||
|
if (currentSequence[checkIteration] != '\n' && currentSequence[checkIteration] != 0x20 && !isdigit(currentSequence[checkIteration]))
|
||||||
{
|
{
|
||||||
// If this occurs, then the first non-whitespace line we read wasn't a number.
|
|
||||||
result = ESStatus::Error;
|
result = ESStatus::Error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else if (currentSequence[checkIteration] != '\n' && currentSequence[checkIteration] != 0x20)
|
||||||
|
result = ESStatus::Good;
|
||||||
|
|
||||||
break;
|
free(temporaryBuffer);
|
||||||
|
if (result == ESStatus::Good)
|
||||||
|
_fInput = FOpen(filename, "r");
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
while(currentSequence = strtok(NULL, "\n"));
|
||||||
|
|
||||||
free(temporaryBuffer);
|
free(temporaryBuffer);
|
||||||
if (result == ESStatus::Good)
|
if (result == ESStatus::Good)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user