-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathbyteswriter_extra_ops.h
More file actions
34 lines (28 loc) · 922 Bytes
/
byteswriter_extra_ops.h
File metadata and controls
34 lines (28 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef BYTESWRITER_EXTRA_OPS_H
#define BYTESWRITER_EXTRA_OPS_H
#include "librt_strings.h"
static inline CPyTagged
CPyBytesWriter_Len(PyObject *obj) {
return (CPyTagged)((BytesWriterObject *)obj)->len << 1;
}
static inline bool
CPyBytesWriter_EnsureSize(BytesWriterObject *data, Py_ssize_t n) {
if (likely(data->capacity - data->len >= n)) {
return true;
} else {
return LibRTStrings_ByteWriter_grow_buffer_internal(data, n);
}
}
static inline char
CPyBytesWriter_Append(PyObject *obj, uint8_t value) {
BytesWriterObject *self = (BytesWriterObject *)obj;
// Store length in a local variable to enable additional optimizations
Py_ssize_t len = self->len;
if (!CPyBytesWriter_EnsureSize(self, 1))
return CPY_NONE_ERROR;
self->buf[len] = value;
self->len = len + 1;
return CPY_NONE;
}
char CPyBytesWriter_Write(PyObject *obj, PyObject *value);
#endif