Minor optimizations in RBuffer.bytes ##performance
Some checks failed
build / linux-wasi (push) Waiting to run
build / linux-wasi-api (push) Waiting to run
build / linux-csnext (push) Waiting to run
build / tarball (push) Waiting to run
build / linux-static (push) Waiting to run
build / linux-acr-rpm-64 (push) Waiting to run
build / linux-acr-deb (amd64) (push) Waiting to run
build / linux-acr-deb (arm64, aarch64-linux-gnu) (push) Waiting to run
build / linux-acr-deb (i386, multilib) (push) Waiting to run
build / macos-acr (arm64, 13) (push) Waiting to run
build / macos-acr (x86_64, 12) (push) Waiting to run
build / ios (cydia32) (push) Waiting to run
build / ios (true, cydia) (push) Waiting to run
build / android-acr (16, arm) (push) Waiting to run
build / android-acr (aarch64) (push) Waiting to run
build / android-meson (x86_64) (push) Waiting to run
build / w32-meson (push) Waiting to run
build / w64-static-2022 (push) Waiting to run
build / w64-static (push) Waiting to run
build / w64-meson (push) Waiting to run
build / check_abi_compatibility (push) Blocked by required conditions
build / check_release (push) Blocked by required conditions
build / release (push) Blocked by required conditions
CI / linux-acr-oldlibsbug (push) Waiting to run
CI / linux-nocs (push) Waiting to run
CI / linux-acr-gperf (push) Waiting to run
CI / linux-sys-capstone (push) Waiting to run
CI / linux-acr-resymlink (push) Waiting to run
CI / linux-test (push) Waiting to run
CI / linux-static-meson (push) Waiting to run
CI / macos-test (push) Waiting to run
CI / linux-rpath (push) Waiting to run
CI / macos-rpath (push) Waiting to run
CI / linux-meson-spaces (push) Waiting to run
CI / linux-tinyasan-fuzz (push) Waiting to run
CI / linux-asan-fuzz (push) Waiting to run
CI / w64-make (push) Waiting to run
CI / w32-mingw (push) Waiting to run
CI / w64-mingw (push) Waiting to run
Coverity Scan / latest (push) Waiting to run
tcc / ubuntu-tcc-newabi (push) Waiting to run
tcc / ubuntu-tcc-test (push) Waiting to run
tcc / ubuntu-tcc-nodbg (push) Waiting to run
tcc / r2pm-tcc (push) Waiting to run
tcc / ubuntu-tcc-syslibs (push) Waiting to run
Code scanning - action / CodeQL-Build (push) Has been cancelled

This commit is contained in:
pancake 2024-10-20 10:30:08 +02:00 committed by GitHub
parent 3e6f559942
commit 6e7be051dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 6 deletions

View File

@ -641,6 +641,12 @@ R_API st64 r_buf_fwrite_at(RBuffer *b, ut64 addr, const ut8 *buf, const char *fm
return r;
}
#if R2_600
R_API ut64 r_buf_at(RBuffer *b) {
return r_buf_seek (b, 0, R_BUF_CUR);
}
#endif
R_API st64 r_buf_read_at(RBuffer *b, ut64 addr, ut8 *buf, ut64 len) {
R_RETURN_VAL_IF_FAIL (b && buf, -1);
st64 o_addr = r_buf_seek (b, 0, R_BUF_CUR);

View File

@ -90,7 +90,8 @@ static st64 buf_bytes_read(RBuffer *b, ut8 *buf, ut64 len) {
return 0;
}
ut64 real_len = priv->length < priv->offset? 0: R_MIN (priv->length - priv->offset, len);
memmove (buf, priv->buf + priv->offset, real_len);
// memmove (buf, priv->buf + priv->offset, real_len);
memcpy (buf, priv->buf + priv->offset, real_len);
priv->offset += real_len;
return real_len;
}
@ -115,7 +116,7 @@ static ut64 buf_bytes_get_size(RBuffer *b) {
static st64 buf_bytes_seek(RBuffer *b, st64 addr, int whence) {
struct buf_bytes_priv *priv = get_priv_bytes (b);
if (addr < 0) {
if (R_UNLIKELY (addr < 0)) {
if (addr > -UT48_MAX) {
if (-addr > (st64)priv->offset) {
return -1;
@ -124,17 +125,19 @@ static st64 buf_bytes_seek(RBuffer *b, st64 addr, int whence) {
return -1;
}
}
ut64 po = priv->offset;
if (R_LIKELY (whence == R_BUF_SET)) {
// 50%
priv->offset = addr;
po = addr;
} else if (whence == R_BUF_CUR) {
// 20%
priv->offset += addr;
po += addr;
} else {
// 5%
priv->offset = priv->length + addr;
po = priv->length + addr;
}
return priv->offset;
priv->offset = po;
return po;
}
static ut8 *buf_bytes_get_whole_buf(RBuffer *b, ut64 *sz) {