diff options
| author | Congcong Kuo <congcong.kuo@gmail.com> | 2025-05-27 01:49:56 +0800 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-05-28 19:31:45 +0200 |
| commit | 583e0688e33c4f3d7e3f1e2f30dd78690eb58fd4 (patch) | |
| tree | 4540726ce9e891cce45887e2459de173436d6b62 /nix | |
| parent | c29534228ff9ac74e8c6a0e80356c21adbff9887 (diff) | |
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>
Diffstat (limited to 'nix')
| -rw-r--r-- | nix/libutil/serialise.cc | 19 | ||||
| -rw-r--r-- | nix/libutil/util.cc | 7 | ||||
| -rw-r--r-- | nix/libutil/util.hh | 12 |
3 files changed, 12 insertions, 26 deletions
diff --git a/nix/libutil/serialise.cc b/nix/libutil/serialise.cc index 92417507508..6f04ab15918 100644 --- a/nix/libutil/serialise.cc +++ b/nix/libutil/serialise.cc | |||
| @@ -16,11 +16,11 @@ BufferedSink::~BufferedSink() | |||
| 16 | delete[] buffer; | 16 | delete[] buffer; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | void BufferedSink::operator () (const unsigned char * data, size_t len) | 20 | void BufferedSink::operator () (const unsigned char * data, size_t len) |
| 21 | { | 21 | { |
| 22 | if (!buffer) buffer = new unsigned char[bufSize]; | 22 | if (!buffer) buffer = new unsigned char[bufSize]; |
| 23 | 23 | ||
| 24 | while (len) { | 24 | while (len) { |
| 25 | /* Optimisation: bypass the buffer if the data exceeds the | 25 | /* Optimisation: bypass the buffer if the data exceeds the |
| 26 | buffer size. */ | 26 | buffer size. */ |
| @@ -96,7 +96,7 @@ size_t BufferedSource::read(unsigned char * data, size_t len) | |||
| 96 | if (!buffer) buffer = new unsigned char[bufSize]; | 96 | if (!buffer) buffer = new unsigned char[bufSize]; |
| 97 | 97 | ||
| 98 | if (!bufPosIn) bufPosIn = readUnbuffered(buffer, bufSize); | 98 | if (!bufPosIn) bufPosIn = readUnbuffered(buffer, bufSize); |
| 99 | 99 | ||
| 100 | /* Copy out the data in the buffer. */ | 100 | /* Copy out the data in the buffer. */ |
| 101 | size_t n = len > bufPosIn - bufPosOut ? bufPosIn - bufPosOut : len; | 101 | size_t n = len > bufPosIn - bufPosOut ? bufPosIn - bufPosOut : len; |
| 102 | memcpy(data, buffer + bufPosOut, n); | 102 | memcpy(data, buffer + bufPosOut, n); |
| @@ -247,18 +247,17 @@ size_t readString(unsigned char * buf, size_t max, Source & source) | |||
| 247 | return len; | 247 | return len; |
| 248 | } | 248 | } |
| 249 | 249 | ||
| 250 | 250 | ||
| 251 | string readString(Source & source) | 251 | string readString(Source & source) |
| 252 | { | 252 | { |
| 253 | size_t len = readInt(source); | 253 | size_t len = readInt(source); |
| 254 | unsigned char * buf = new unsigned char[len]; | 254 | std::vector<unsigned char> buf(len); |
| 255 | AutoDeleteArray<unsigned char> d(buf); | 255 | source(buf.data(), buf.size()); |
| 256 | source(buf, len); | 256 | readPadding(buf.size(), source); |
| 257 | readPadding(len, source); | 257 | return string((char *) buf.data(), buf.size()); |
| 258 | return string((char *) buf, len); | ||
| 259 | } | 258 | } |
| 260 | 259 | ||
| 261 | 260 | ||
| 262 | template<class T> T readStrings(Source & source) | 261 | template<class T> T readStrings(Source & source) |
| 263 | { | 262 | { |
| 264 | unsigned int count = readInt(source); | 263 | unsigned int count = readInt(source); |
diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc index 56f116046c4..398f61841f1 100644 --- a/nix/libutil/util.cc +++ b/nix/libutil/util.cc | |||
| @@ -271,11 +271,10 @@ string readFile(int fd) | |||
| 271 | if (fstat(fd, &st) == -1) | 271 | if (fstat(fd, &st) == -1) |
| 272 | throw SysError("statting file"); | 272 | throw SysError("statting file"); |
| 273 | 273 | ||
| 274 | unsigned char * buf = new unsigned char[st.st_size]; | 274 | std::vector<unsigned char> buf(st.st_size); |
| 275 | AutoDeleteArray<unsigned char> d(buf); | 275 | readFull(fd, buf.data(), buf.size()); |
| 276 | readFull(fd, buf, st.st_size); | ||
| 277 | 276 | ||
| 278 | return string((char *) buf, st.st_size); | 277 | return string((char *) buf.data(), buf.size()); |
| 279 | } | 278 | } |
| 280 | 279 | ||
| 281 | 280 | ||
diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh index 377aac06847..03234e3a5d2 100644 --- a/nix/libutil/util.hh +++ b/nix/libutil/util.hh | |||
| @@ -194,18 +194,6 @@ string drainFD(int fd); | |||
| 194 | /* Automatic cleanup of resources. */ | 194 | /* Automatic cleanup of resources. */ |
| 195 | 195 | ||
| 196 | 196 | ||
| 197 | template <class T> | ||
| 198 | struct AutoDeleteArray | ||
| 199 | { | ||
| 200 | T * p; | ||
| 201 | AutoDeleteArray(T * p) : p(p) { } | ||
| 202 | ~AutoDeleteArray() | ||
| 203 | { | ||
| 204 | delete [] p; | ||
| 205 | } | ||
| 206 | }; | ||
| 207 | |||
| 208 | |||
| 209 | class AutoDelete | 197 | class AutoDelete |
| 210 | { | 198 | { |
| 211 | Path path; | 199 | Path path; |
