Optimized String usage

It will no longer initialize the buffer if not necessary


Former-commit-id: b8c910268ed3db6affb8f88b45d043d1dc021aa7
This commit is contained in:
Lynix 2014-03-15 00:26:29 +01:00
parent 268d3ae86d
commit 970c0c8ef8
5 changed files with 9 additions and 13 deletions

View File

@ -47,10 +47,10 @@ NzString NzInputStream::ReadLine(unsigned int lineSize)
}
else
{
line.Resize(lineSize);
line.Set(lineSize, '\0');
unsigned int readSize = Read(&line[0], lineSize);
unsigned int pos = line.Find('\n');
if (pos <= readSize) // Forcément trouvé, npos étant le plus grand des entiers
if (pos <= readSize) // Faux uniquement si le caractère n'est pas présent (npos étant le plus grand entier)
{
if (m_streamOptions & nzStreamOption_Text && pos > 0 && line[pos-1] == '\r')
line.Resize(pos);

View File

@ -238,8 +238,7 @@ bool NzLuaInstance::ExecuteFromFile(const NzString& filePath)
unsigned int length = static_cast<unsigned int>(file.GetSize());
NzString source;
source.Resize(length);
NzString source(length, '\0');
if (file.Read(&source[0], length) != length)
{

View File

@ -233,7 +233,7 @@ NzString NzShader::GetLog() const
glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &length);
if (length > 1) // Le caractère de fin faisant partie du compte
{
log.Resize(length - 1); // La taille retournée est celle du buffer (Avec caractère de fin)
log.Set(length - 1, '\0'); // La taille retournée est celle du buffer (Avec caractère de fin)
glGetProgramInfoLog(m_program, length, nullptr, &log[0]);
}
else
@ -262,8 +262,7 @@ NzString NzShader::GetSourceCode(nzShaderStage stage) const
totalLength += (m_attachedShaders[stage].size()-1)*(sizeof(sep)/sizeof(char));
NzString source;
source.Resize(totalLength);
NzString source(totalLength, '\0');
unsigned int offset = 0;
for (unsigned int shader : m_attachedShaders[stage])

View File

@ -93,7 +93,7 @@ NzString NzShaderStage::GetLog() const
glGetShaderiv(m_id, GL_INFO_LOG_LENGTH, &length);
if (length > 1) // Le caractère de fin faisant partie du compte
{
log.Resize(length - 1); // La taille retournée est celle du buffer (Avec caractère de fin)
log.Set(length - 1, '\0'); // La taille retournée est celle du buffer (Avec caractère de fin)
glGetShaderInfoLog(m_id, length, nullptr, &log[0]);
}
else
@ -118,7 +118,7 @@ NzString NzShaderStage::GetSource() const
glGetShaderiv(m_id, GL_SHADER_SOURCE_LENGTH, &length);
if (length > 1) // Le caractère de fin compte
{
source.Resize(length - 1); // La taille retournée est celle du buffer (Avec caractère de fin)
source.Set(length - 1, '\0'); // La taille retournée est celle du buffer (Avec caractère de fin)
glGetShaderSource(m_id, length, nullptr, &source[0]);
}
@ -182,8 +182,7 @@ bool NzShaderStage::SetSourceFromFile(const NzString& filePath)
unsigned int length = static_cast<unsigned int>(file.GetSize());
NzString source;
source.Resize(length);
NzString source(length, '\0');
if (file.Read(&source[0], length) != length)
{

View File

@ -139,8 +139,7 @@ bool NzUberShaderPreprocessor::SetShaderFromFile(nzShaderStage stage, const NzSt
unsigned int length = static_cast<unsigned int>(file.GetSize());
NzString source;
source.Resize(length);
NzString source(length, '\0');
if (file.Read(&source[0], length) != length)
{