mirror of
https://codeberg.org/guix/guix.git
synced 2025-10-02 02:15:12 +00:00
daemon: Remove ‘AutoDeleteArray’.
* libutil/util.hh (AutoDeleteArray): Remove. * libutil/util.cc (readString, readStrings): Use ‘std::vector’ instead of ‘AutoDeleteArray’. * libutil/serialise.cc (readFile): Likewise. Change-Id: I45362998dbb8226874f66b77cd19f071f7bb2ab3 Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
c29534228f
commit
583e0688e3
3 changed files with 12 additions and 26 deletions
|
@ -16,11 +16,11 @@ BufferedSink::~BufferedSink()
|
|||
delete[] buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BufferedSink::operator () (const unsigned char * data, size_t len)
|
||||
{
|
||||
if (!buffer) buffer = new unsigned char[bufSize];
|
||||
|
||||
|
||||
while (len) {
|
||||
/* Optimisation: bypass the buffer if the data exceeds the
|
||||
buffer size. */
|
||||
|
@ -96,7 +96,7 @@ size_t BufferedSource::read(unsigned char * data, size_t len)
|
|||
if (!buffer) buffer = new unsigned char[bufSize];
|
||||
|
||||
if (!bufPosIn) bufPosIn = readUnbuffered(buffer, bufSize);
|
||||
|
||||
|
||||
/* Copy out the data in the buffer. */
|
||||
size_t n = len > bufPosIn - bufPosOut ? bufPosIn - bufPosOut : len;
|
||||
memcpy(data, buffer + bufPosOut, n);
|
||||
|
@ -247,18 +247,17 @@ size_t readString(unsigned char * buf, size_t max, Source & source)
|
|||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
string readString(Source & source)
|
||||
{
|
||||
size_t len = readInt(source);
|
||||
unsigned char * buf = new unsigned char[len];
|
||||
AutoDeleteArray<unsigned char> d(buf);
|
||||
source(buf, len);
|
||||
readPadding(len, source);
|
||||
return string((char *) buf, len);
|
||||
std::vector<unsigned char> buf(len);
|
||||
source(buf.data(), buf.size());
|
||||
readPadding(buf.size(), source);
|
||||
return string((char *) buf.data(), buf.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class T> T readStrings(Source & source)
|
||||
{
|
||||
unsigned int count = readInt(source);
|
||||
|
|
|
@ -271,11 +271,10 @@ string readFile(int fd)
|
|||
if (fstat(fd, &st) == -1)
|
||||
throw SysError("statting file");
|
||||
|
||||
unsigned char * buf = new unsigned char[st.st_size];
|
||||
AutoDeleteArray<unsigned char> d(buf);
|
||||
readFull(fd, buf, st.st_size);
|
||||
std::vector<unsigned char> buf(st.st_size);
|
||||
readFull(fd, buf.data(), buf.size());
|
||||
|
||||
return string((char *) buf, st.st_size);
|
||||
return string((char *) buf.data(), buf.size());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -194,18 +194,6 @@ string drainFD(int fd);
|
|||
/* Automatic cleanup of resources. */
|
||||
|
||||
|
||||
template <class T>
|
||||
struct AutoDeleteArray
|
||||
{
|
||||
T * p;
|
||||
AutoDeleteArray(T * p) : p(p) { }
|
||||
~AutoDeleteArray()
|
||||
{
|
||||
delete [] p;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AutoDelete
|
||||
{
|
||||
Path path;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue