Expose buffer_root()

This commit is contained in:
Ryan Dahl 2010-01-24 14:06:07 -08:00
parent 42ee16978e
commit bffa18befc
2 changed files with 6 additions and 6 deletions

View File

@ -32,10 +32,6 @@ bool IsBuffer(v8::Handle<v8::Value> val) {
}
static inline struct buffer* buffer_root(buffer *buffer) {
return buffer->root ? buffer->root : buffer;
}
/* Determines the absolute position for a relative offset */
static inline size_t buffer_abs_off(buffer *buffer, size_t off) {
struct buffer *root = buffer_root(buffer);

View File

@ -40,14 +40,18 @@ void InitBuffer(v8::Handle<v8::Object> target);
struct buffer* BufferUnwrap(v8::Handle<v8::Value> val);
bool IsBuffer(v8::Handle<v8::Value> val);
static inline struct buffer * buffer_root(struct buffer *buffer) {
return buffer->root ? buffer->root : buffer;
}
static inline char * buffer_p(struct buffer *buffer, size_t off) {
struct buffer *root = buffer->root ? buffer->root : buffer;
struct buffer *root = buffer_root(buffer);
if (buffer->offset + off >= root->length) return NULL;
return reinterpret_cast<char*>(&(root->bytes) + buffer->offset + off);
}
static inline size_t buffer_remaining(struct buffer *buffer, size_t off) {
struct buffer *root = buffer->root ? buffer->root : buffer;
struct buffer *root = buffer_root(buffer);
char *end = reinterpret_cast<char*>(&(root->bytes) + root->length);
return end - buffer_p(buffer, off);
}