Browse Source

Expose buffer_root()

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
bffa18befc
  1. 4
      src/node_buffer.cc
  2. 8
      src/node_buffer.h

4
src/node_buffer.cc

@ -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 */ /* Determines the absolute position for a relative offset */
static inline size_t buffer_abs_off(buffer *buffer, size_t off) { static inline size_t buffer_abs_off(buffer *buffer, size_t off) {
struct buffer *root = buffer_root(buffer); struct buffer *root = buffer_root(buffer);

8
src/node_buffer.h

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

Loading…
Cancel
Save