# some fixes to reduce the size of the binary. Total savings are ~3%. Thanks to Krishty for his efforts in that regard.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@939 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2011-04-03 15:12:05 +00:00
parent 45d6647ffe
commit 85cd9be46d
7 changed files with 62 additions and 31 deletions

View File

@ -31,7 +31,7 @@ namespace boost
{ {
// XXX add replacement for boost::lexical_cast? // XXX add replacement for boost::lexical_cast?
std::stringstream ss; std::ostringstream ss;
ss << in; // note: ss cannot be an rvalue, or the global operator << (const char*) is not called for T == const char*. ss << in; // note: ss cannot be an rvalue, or the global operator << (const char*) is not called for T == const char*.
chunks.push_back( ss.str()); chunks.push_back( ss.str());
return *this; return *this;

View File

@ -159,47 +159,49 @@ Logger *DefaultLogger::create(const char* name /*= "AssimpLog.txt"*/,
} }
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
void Logger::debug(const std::string &message) { void Logger::debug(const char* message) {
// SECURITY FIX: otherwise it's easy to produce overruns ... // SECURITY FIX: otherwise it's easy to produce overruns since
if (message.length()>MAX_LOG_MESSAGE_LENGTH) { // sometimes importers will include data from the input file
// (i.e. node names) in their messages.
if (strlen(message)>MAX_LOG_MESSAGE_LENGTH) {
ai_assert(false); ai_assert(false);
return; return;
} }
return OnDebug(message.c_str()); return OnDebug(message);
} }
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
void Logger::info(const std::string &message) { void Logger::info(const char* message) {
// SECURITY FIX: otherwise it's easy to produce overruns ... // SECURITY FIX: see above
if (message.length()>MAX_LOG_MESSAGE_LENGTH) { if (strlen(message)>MAX_LOG_MESSAGE_LENGTH) {
ai_assert(false); ai_assert(false);
return; return;
} }
return OnInfo(message.c_str()); return OnInfo(message);
} }
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
void Logger::warn(const std::string &message) { void Logger::warn(const char* message) {
// SECURITY FIX: otherwise it's easy to produce overruns ... // SECURITY FIX: see above
if (message.length()>MAX_LOG_MESSAGE_LENGTH) { if (strlen(message)>MAX_LOG_MESSAGE_LENGTH) {
ai_assert(false); ai_assert(false);
return; return;
} }
return OnWarn(message.c_str()); return OnWarn(message);
} }
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
void Logger::error(const std::string &message) { void Logger::error(const char* message) {
// SECURITY FIX: otherwise it's easy to produce overruns ... // SECURITY FIX: see above
if (message.length()>MAX_LOG_MESSAGE_LENGTH) { if (strlen(message)>MAX_LOG_MESSAGE_LENGTH) {
ai_assert(false); ai_assert(false);
return; return;
} }
return OnError(message.c_str()); return OnError(message);
} }
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------

View File

@ -1097,7 +1097,8 @@ void LWOImporter::LoadLWO2Clip(unsigned int length)
int16_t offset = GetU2(); mFileBuffer+=4; int16_t offset = GetU2(); mFileBuffer+=4;
int16_t start = GetU2(); mFileBuffer+=4; int16_t start = GetU2(); mFileBuffer+=4;
std::string s;std::stringstream ss; std::string s;
std::ostringstream ss;
GetS0(s,head->length); GetS0(s,head->length);
head->length -= (unsigned int)s.length()+1; head->length -= (unsigned int)s.length()+1;

View File

@ -221,7 +221,7 @@ void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader)
{ {
//some info logging: //some info logging:
unsigned int NumFaces=GetAttribute<int>(Reader, "count"); unsigned int NumFaces=GetAttribute<int>(Reader, "count");
stringstream ss; ss <<"Submesh has " << NumFaces << " Faces."; ostringstream ss; ss <<"Submesh has " << NumFaces << " Faces.";
DefaultLogger::get()->debug(ss.str()); DefaultLogger::get()->debug(ss.str());
while(XmlRead(Reader) && Reader->getNodeName()==string("face")) while(XmlRead(Reader) && Reader->getNodeName()==string("face"))
@ -242,7 +242,7 @@ void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader)
{ {
//some info logging: //some info logging:
unsigned int NumVertices=GetAttribute<int>(Reader, "vertexcount"); unsigned int NumVertices=GetAttribute<int>(Reader, "vertexcount");
stringstream ss; ss<<"VertexCount: "<<NumVertices; ostringstream ss; ss<<"VertexCount: "<<NumVertices;
DefaultLogger::get()->debug(ss.str()); DefaultLogger::get()->debug(ss.str());
//General Informations about vertices //General Informations about vertices

View File

@ -68,7 +68,7 @@ static const std::string Q3BSPExtension = "pk3";
// Local function to create a material key name. // Local function to create a material key name.
static void createKey( int id1, int id2, std::string &rKey ) static void createKey( int id1, int id2, std::string &rKey )
{ {
std::stringstream str; std::ostringstream str;
str << id1 << "." << id2; str << id1 << "." << id2;
rKey = str.str(); rKey = str.str();
} }

View File

@ -94,22 +94,26 @@ public:
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** @brief Writes a debug message /** @brief Writes a debug message
* @param message Debug message*/ * @param message Debug message*/
void debug(const std::string &message); void debug(const char* message);
inline void debug(const std::string &message);
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** @brief Writes a info message /** @brief Writes a info message
* @param message Info message*/ * @param message Info message*/
void info(const std::string &message); void info(const char* message);
inline void info(const std::string &message);
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** @brief Writes a warning message /** @brief Writes a warning message
* @param message Warn message*/ * @param message Warn message*/
void warn(const std::string &message); void warn(const char* message);
inline void warn(const std::string &message);
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** @brief Writes an error message /** @brief Writes an error message
* @param message Error message*/ * @param message Error message*/
void error(const std::string &message); void error(const char* message);
inline void error(const std::string &message);
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** @brief Set a new log severity. /** @brief Set a new log severity.
@ -227,6 +231,30 @@ inline Logger::LogSeverity Logger::getLogSeverity() const {
return m_Severity; return m_Severity;
} }
// ----------------------------------------------------------------------------------
inline void Logger::debug(const std::string &message)
{
return debug(message.c_str());
}
// ----------------------------------------------------------------------------------
inline void Logger::error(const std::string &message)
{
return error(message.c_str());
}
// ----------------------------------------------------------------------------------
inline void Logger::warn(const std::string &message)
{
return warn(message.c_str());
}
// ----------------------------------------------------------------------------------
inline void Logger::info(const std::string &message)
{
return info(message.c_str());
}
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
} // Namespace Assimp } // Namespace Assimp

View File

@ -219,7 +219,7 @@ struct aiColor3D
* *
* The character set of an aiString is explicitly defined to be UTF-8. This Unicode * The character set of an aiString is explicitly defined to be UTF-8. This Unicode
* transformation was chosen in the belief that most strings in 3d files are limited * transformation was chosen in the belief that most strings in 3d files are limited
* to the ASCII characters, thus the character set needed to be ASCII compatible. * to ASCII, thus the character set needed to be strictly ASCII compatible.
* *
* Most text file loaders provide proper Unicode input file handling, special unicode * Most text file loaders provide proper Unicode input file handling, special unicode
* characters are correctly transcoded to UTF8 and are kept throughout the libraries' * characters are correctly transcoded to UTF8 and are kept throughout the libraries'
@ -275,7 +275,7 @@ struct aiString
return; return;
} }
length = pString.length(); length = pString.length();
::memcpy( data, pString.c_str(), length); memcpy( data, pString.c_str(), length);
data[length] = 0; data[length] = 0;
} }
@ -286,7 +286,7 @@ struct aiString
return; return;
} }
length = len; length = len;
::memcpy( data, sz, len); memcpy( data, sz, len);
data[len] = 0; data[len] = 0;
} }
@ -304,17 +304,17 @@ struct aiString
/** Comparison operator */ /** Comparison operator */
bool operator==(const aiString& other) const { bool operator==(const aiString& other) const {
return (length == other.length && 0 == strcmp(this->data,other.data)); return (length == other.length && 0 == memcmp(data,other.data,length));
} }
/** Inverse comparison operator */ /** Inverse comparison operator */
bool operator!=(const aiString& other) const { bool operator!=(const aiString& other) const {
return (length != other.length || 0 != ::strcmp(this->data,other.data)); return (length != other.length || 0 != memcmp(data,other.data,length));
} }
/** Append a string to the string */ /** Append a string to the string */
void Append (const char* app) { void Append (const char* app) {
const size_t len = ::strlen(app); const size_t len = strlen(app);
if (!len) { if (!len) {
return; return;
} }