avoid reopen file

This commit is contained in:
yangxiao 2014-06-16 18:46:58 +08:00
parent 0c07b05e1d
commit 2c6f7b63d1
2 changed files with 15 additions and 9 deletions

View File

@ -109,17 +109,22 @@ void Bundle3D::purgeBundle3D()
bool Bundle3D::load(const std::string& path)
{
std::string strFileString = FileUtils::getInstance()->getStringFromFile(path);
ssize_t size = strFileString.length();
CC_SAFE_DELETE_ARRAY(_documentBuffer);
_documentBuffer = new char[size + 1];
memcpy(_documentBuffer, strFileString.c_str(), size);
_documentBuffer[size] = '\0';
if (document.ParseInsitu<0>(_documentBuffer).HasParseError())
if (strFileString != _fullPath)
{
assert(0);
return false;
ssize_t size = strFileString.length();
CC_SAFE_DELETE_ARRAY(_documentBuffer);
_documentBuffer = new char[size + 1];
memcpy(_documentBuffer, strFileString.c_str(), size);
_documentBuffer[size] = '\0';
if (document.ParseInsitu<0>(_documentBuffer).HasParseError())
{
assert(0);
return false;
}
_fullPath = strFileString;
}
return true;
}

View File

@ -94,6 +94,7 @@ protected:
char* _documentBuffer;
rapidjson::Document document;
std::string _fullPath;
bool _isBinary;
};