Skip to content

Commit

Permalink
vector to unique_ptr
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jan 30, 2025
1 parent 8ec4f77 commit 5a08565
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,10 +963,10 @@ std::string XPathIo::writeDataToFile(const std::string& orgPath) {
}

std::string data = orgPath.substr(base64Pos + 7);
std::vector<char> decodeData(data.length());
auto size = base64decode(data.c_str(), decodeData.data(), data.length());
auto decodeData = std::make_unique<char[]>(data.length());
auto size = base64decode(data.c_str(), decodeData.get(), data.length());
if (size > 0) {
fs.write(decodeData.data(), size);
fs.write(decodeData.get(), size);
fs.close();
} else {
fs.close();
Expand Down Expand Up @@ -1151,7 +1151,7 @@ size_t RemoteIo::write(BasicIo& src) {
size_t left = 0;
size_t right = 0;
size_t blockIndex = 0;
std::vector<byte> buf(p_->blockSize_);
auto buf = std::make_unique<byte[]>(p_->blockSize_);
size_t nBlocks = (p_->size_ + p_->blockSize_ - 1) / p_->blockSize_;

// find $left
Expand All @@ -1160,7 +1160,7 @@ size_t RemoteIo::write(BasicIo& src) {
while (blockIndex < nBlocks && !src.eof() && !findDiff) {
size_t blockSize = p_->blocksMap_[blockIndex].getSize();
bool isFakeData = p_->blocksMap_[blockIndex].isKnown(); // fake data
size_t readCount = src.read(buf.data(), blockSize);
size_t readCount = src.read(buf.get(), blockSize);
auto blockData = p_->blocksMap_[blockIndex].getData();
for (size_t i = 0; (i < readCount) && (i < blockSize) && !findDiff; i++) {
if ((!isFakeData && buf[i] != blockData[i]) || (isFakeData && buf[i] != 0)) {
Expand All @@ -1182,7 +1182,7 @@ size_t RemoteIo::write(BasicIo& src) {
findDiff = true;
} else {
bool isFakeData = p_->blocksMap_[blockIndex].isKnown(); // fake data
size_t readCount = src.read(buf.data(), blockSize);
size_t readCount = src.read(buf.get(), blockSize);
auto blockData = p_->blocksMap_[blockIndex].getData();
for (size_t i = 0; (i < readCount) && (i < blockSize) && !findDiff; i++) {
if ((!isFakeData && buf[readCount - i - 1] != blockData[blockSize - i - 1]) ||
Expand All @@ -1197,10 +1197,10 @@ size_t RemoteIo::write(BasicIo& src) {

// submit to the remote machine.
if (auto dataSize = src.size() - left - right) {
std::vector<byte> data(dataSize);
auto data = std::make_unique<byte[]>(dataSize);
src.seek(left, BasicIo::beg);
src.read(data.data(), dataSize);
p_->writeRemote(data.data(), dataSize, left, p_->size_ - right);
src.read(data.get(), dataSize);
p_->writeRemote(data.get(), dataSize, left, p_->size_ - right);
}
return src.size();
}
Expand Down Expand Up @@ -1468,10 +1468,10 @@ void HttpIo::HttpImpl::writeRemote(const byte* data, size_t size, size_t from, s

// encode base64
size_t encodeLength = (((size + 2) / 3) * 4) + 1;
std::vector<char> encodeData(encodeLength);
base64encode(data, size, encodeData.data(), encodeLength);
auto encodeData = std::make_unique<char[]>(encodeLength);
base64encode(data, size, encodeData.get(), encodeLength);
// url encode
const std::string urlencodeData = urlencode(encodeData.data());
const std::string urlencodeData = urlencode(encodeData.get());

auto postData = stringFormat("path={}&from={}&to={}&data={}", hostInfo_.Path, from, to, urlencodeData);

Expand Down Expand Up @@ -1644,10 +1644,10 @@ void CurlIo::CurlImpl::writeRemote(const byte* data, size_t size, size_t from, s

// encode base64
size_t encodeLength = (((size + 2) / 3) * 4) + 1;
std::vector<char> encodeData(encodeLength);
base64encode(data, size, encodeData.data(), encodeLength);
auto encodeData = std::make_unique<char[]>(encodeLength);
base64encode(data, size, encodeData.get(), encodeLength);
// url encode
const std::string urlencodeData = urlencode(encodeData.data());
const std::string urlencodeData = urlencode(encodeData.get());
auto postData = stringFormat("path={}&from={}&to={}&data={}", hostInfo.Path, from, to, urlencodeData);

curl_easy_setopt(curl_, CURLOPT_POSTFIELDS, postData.c_str());
Expand Down

0 comments on commit 5a08565

Please sign in to comment.