From 2c6f7b63d18294fa2317d3f7c4a42088e9200143 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Mon, 16 Jun 2014 18:46:58 +0800 Subject: [PATCH] avoid reopen file --- cocos/3d/CCBundle3D.cpp | 23 ++++++++++++++--------- cocos/3d/CCBundle3D.h | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index 155817e247..6495b2d0d5 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -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; } diff --git a/cocos/3d/CCBundle3D.h b/cocos/3d/CCBundle3D.h index ba124da7dd..5188873c4b 100644 --- a/cocos/3d/CCBundle3D.h +++ b/cocos/3d/CCBundle3D.h @@ -94,6 +94,7 @@ protected: char* _documentBuffer; rapidjson::Document document; + std::string _fullPath; bool _isBinary; };