Browse Source

RagePhoto: improve save efficiency by using std::string as buffer

test
Syping 2 months ago
parent
commit
c89296c775
  1. 16
      src/RagePhoto.cpp
  2. 16
      src/RagePhotoA.h

16
src/RagePhoto.cpp

@ -743,24 +743,18 @@ bool RagePhoto::save(char *data)
const std::string RagePhoto::save(uint32_t photoFormat, bool *ok)
{
std::string data;
const size_t size = saveSize(photoFormat);
if (size == 0) {
if (ok)
*ok = false;
return std::string();
}
char *data = static_cast<char*>(std::malloc(size));
if (!data) {
if (ok)
*ok = false;
return std::string();
return data;
}
const bool saved = save(data, photoFormat);
data.resize(size);
const bool saved = save(&data[0], photoFormat);
if (ok)
*ok = saved;
const std::string sdata = std::string(data, size);
std::free(data);
return sdata;
return data;
}
const std::string RagePhoto::save(bool *ok)

16
src/RagePhotoA.h

@ -88,24 +88,18 @@ public:
return ragephoto_save(instance, data);
}
const std::string save(uint32_t photoFormat, bool *ok = nullptr) {
std::string data;
const size_t size = ragephoto_getsavesizef(instance, photoFormat);
if (size == 0) {
if (ok)
*ok = false;
return std::string();
return data;
}
char *data = static_cast<char*>(std::malloc(size));
if (!data) {
if (ok)
*ok = false;
return std::string();
}
const bool saved = ragephoto_savef(instance, data, photoFormat);
data.resize(size);
const bool saved = ragephoto_savef(instance, &data[0], photoFormat);
if (ok)
*ok = saved;
const std::string sdata = std::string(data, size);
std::free(data);
return sdata;
return data;
}
const std::string save(bool *ok = nullptr) {
return save(ragephoto_getphotoformat(instance), ok);

Loading…
Cancel
Save