From f76211509f2fede4b840b6b4c88d6aa4a228022d Mon Sep 17 00:00:00 2001 From: heckflosse Date: Thu, 7 Jul 2016 21:44:44 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Improve=20processing=20time=20to=20read=20c?= =?UTF-8?q?amconst.json=20by=20almost=20factor=202.=20Additionally=20make?= =?UTF-8?q?=20it=20future-proof=20by=20reducing=20O(n=C2=B2)=20copying=20a?= =?UTF-8?q?mount=20in=20reallocate=20phase=20to=20O(n)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rtengine/camconst.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/rtengine/camconst.cc b/rtengine/camconst.cc index 8290fe085..7342e85b3 100644 --- a/rtengine/camconst.cc +++ b/rtengine/camconst.cc @@ -550,7 +550,8 @@ CameraConstantsStore::parse_camera_constants_file(Glib::ustring filename_) return false; } - size_t bufsize = 4096; + size_t bufsize = 16384; + size_t increment = 2 * bufsize; size_t datasize = 0, ret; char *buf = (char *)malloc(bufsize); @@ -558,8 +559,9 @@ CameraConstantsStore::parse_camera_constants_file(Glib::ustring filename_) datasize += ret; if (datasize == bufsize) { - bufsize += 4096; + bufsize += increment; buf = (char *)realloc(buf, bufsize); + increment *= 2; } } @@ -571,7 +573,11 @@ CameraConstantsStore::parse_camera_constants_file(Glib::ustring filename_) } fclose(stream); - buf = (char *)realloc(buf, datasize + 1); + + if(datasize == bufsize) { + buf = (char *)realloc(buf, datasize + 1); + } + buf[datasize] = '\0'; // remove comments @@ -637,18 +643,17 @@ CameraConstantsStore::parse_camera_constants_file(Glib::ustring filename_) Glib::ustring make_model(ji->valuestring); make_model = make_model.uppercase(); - std::map::iterator existingccIter = mCameraConstants.find(make_model); - if (existingccIter == mCameraConstants.end()) { - // add the new CamConst to the map - mCameraConstants.insert(std::pair(make_model, cc)); + std::pair::iterator, bool> ret; + ret = mCameraConstants.insert(std::pair(make_model, cc)); + if(ret.second) { // entry inserted into map if (settings->verbose) { printf("Add camera constants for \"%s\"\n", make_model.c_str()); } } else { // The CameraConst already exist for this camera make/model -> we merge the values - CameraConst *existingcc = existingccIter->second; + CameraConst *existingcc = ret.first->second; // updating the dcraw matrix existingcc->update_dcrawMatrix(cc->get_dcrawMatrix()); From ed7ee021502bfb3efedaf32e3d1cc2e03f1dc5bc Mon Sep 17 00:00:00 2001 From: heckflosse Date: Thu, 7 Jul 2016 22:31:04 +0200 Subject: [PATCH 2/2] Added change suggested by Floessie --- rtengine/camconst.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rtengine/camconst.cc b/rtengine/camconst.cc index 7342e85b3..05db7470b 100644 --- a/rtengine/camconst.cc +++ b/rtengine/camconst.cc @@ -644,8 +644,7 @@ CameraConstantsStore::parse_camera_constants_file(Glib::ustring filename_) Glib::ustring make_model(ji->valuestring); make_model = make_model.uppercase(); - std::pair::iterator, bool> ret; - ret = mCameraConstants.insert(std::pair(make_model, cc)); + const auto ret = mCameraConstants.emplace(make_model, cc); if(ret.second) { // entry inserted into map if (settings->verbose) {