Optimized String usage
It will no longer initialize the buffer if not necessary Former-commit-id: b8c910268ed3db6affb8f88b45d043d1dc021aa7
This commit is contained in:
parent
268d3ae86d
commit
970c0c8ef8
|
|
@ -47,10 +47,10 @@ NzString NzInputStream::ReadLine(unsigned int lineSize)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
line.Resize(lineSize);
|
line.Set(lineSize, '\0');
|
||||||
unsigned int readSize = Read(&line[0], lineSize);
|
unsigned int readSize = Read(&line[0], lineSize);
|
||||||
unsigned int pos = line.Find('\n');
|
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')
|
if (m_streamOptions & nzStreamOption_Text && pos > 0 && line[pos-1] == '\r')
|
||||||
line.Resize(pos);
|
line.Resize(pos);
|
||||||
|
|
|
||||||
|
|
@ -238,8 +238,7 @@ bool NzLuaInstance::ExecuteFromFile(const NzString& filePath)
|
||||||
|
|
||||||
unsigned int length = static_cast<unsigned int>(file.GetSize());
|
unsigned int length = static_cast<unsigned int>(file.GetSize());
|
||||||
|
|
||||||
NzString source;
|
NzString source(length, '\0');
|
||||||
source.Resize(length);
|
|
||||||
|
|
||||||
if (file.Read(&source[0], length) != length)
|
if (file.Read(&source[0], length) != length)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -233,7 +233,7 @@ NzString NzShader::GetLog() const
|
||||||
glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &length);
|
glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &length);
|
||||||
if (length > 1) // Le caractère de fin faisant partie du compte
|
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]);
|
glGetProgramInfoLog(m_program, length, nullptr, &log[0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -262,8 +262,7 @@ NzString NzShader::GetSourceCode(nzShaderStage stage) const
|
||||||
|
|
||||||
totalLength += (m_attachedShaders[stage].size()-1)*(sizeof(sep)/sizeof(char));
|
totalLength += (m_attachedShaders[stage].size()-1)*(sizeof(sep)/sizeof(char));
|
||||||
|
|
||||||
NzString source;
|
NzString source(totalLength, '\0');
|
||||||
source.Resize(totalLength);
|
|
||||||
|
|
||||||
unsigned int offset = 0;
|
unsigned int offset = 0;
|
||||||
for (unsigned int shader : m_attachedShaders[stage])
|
for (unsigned int shader : m_attachedShaders[stage])
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ NzString NzShaderStage::GetLog() const
|
||||||
glGetShaderiv(m_id, GL_INFO_LOG_LENGTH, &length);
|
glGetShaderiv(m_id, GL_INFO_LOG_LENGTH, &length);
|
||||||
if (length > 1) // Le caractère de fin faisant partie du compte
|
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]);
|
glGetShaderInfoLog(m_id, length, nullptr, &log[0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -118,7 +118,7 @@ NzString NzShaderStage::GetSource() const
|
||||||
glGetShaderiv(m_id, GL_SHADER_SOURCE_LENGTH, &length);
|
glGetShaderiv(m_id, GL_SHADER_SOURCE_LENGTH, &length);
|
||||||
if (length > 1) // Le caractère de fin compte
|
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]);
|
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());
|
unsigned int length = static_cast<unsigned int>(file.GetSize());
|
||||||
|
|
||||||
NzString source;
|
NzString source(length, '\0');
|
||||||
source.Resize(length);
|
|
||||||
|
|
||||||
if (file.Read(&source[0], length) != length)
|
if (file.Read(&source[0], length) != length)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -139,8 +139,7 @@ bool NzUberShaderPreprocessor::SetShaderFromFile(nzShaderStage stage, const NzSt
|
||||||
|
|
||||||
unsigned int length = static_cast<unsigned int>(file.GetSize());
|
unsigned int length = static_cast<unsigned int>(file.GetSize());
|
||||||
|
|
||||||
NzString source;
|
NzString source(length, '\0');
|
||||||
source.Resize(length);
|
|
||||||
|
|
||||||
if (file.Read(&source[0], length) != length)
|
if (file.Read(&source[0], length) != length)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue