Skip to content

Commit 4396864

Browse files
committed
Added in utils for making fast buffers
1 parent dd3a9e0 commit 4396864

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

example/raw-blob.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repo.open( path.resolve( '../.git' ), function() {
1818

1919
console.log( entry.name() + ':' );
2020
console.log( blob.rawSize() );
21-
console.log( blob.rawContent() );
21+
console.log( typeof blob.rawContent() );
2222
}
2323
});
2424
});

include/utils.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef UTILS_H
2+
#define UTILS_H
3+
4+
#define MAKE_FAST_BUFFER(NG_SLOW_BUFFER, NG_FAST_BUFFER) \
5+
Local<Function> NG_JS_BUFFER = Local<Function>::Cast( \
6+
Context::GetCurrent()->Global()->Get( \
7+
String::New("Buffer"))); \
8+
\
9+
Handle<Value> NG_JS_ARGS[3] = { \
10+
NG_SLOW_BUFFER->handle_, \
11+
Integer::New(Buffer::Length(NG_SLOW_BUFFER)), \
12+
Integer::New(0) \
13+
}; \
14+
\
15+
NG_FAST_BUFFER = NG_JS_BUFFER->NewInstance(3, NG_JS_ARGS);
16+
17+
#endif

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nodegit",
33
"description": "Node.js libgit2 asynchronous native bindings",
4-
"version": "0.0.4",
4+
"version": "0.0.5",
55
"homepage": "https://github.com/tbranyen/nodegit",
66
"author": "Tim Branyen <tim@tabdeveloper.com> (http://twitter.com/tbranyen)",
77
"main": "./lib/index.js",

src/blob.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "../vendor/libgit2/include/git2.h"
1212

13+
#include "../include/utils.h"
1314
#include "../include/repo.h"
1415
#include "../include/blob.h"
1516

@@ -149,9 +150,13 @@ Handle<Value> GitBlob::RawContent(const Arguments& args) {
149150
int rawSize = blob->RawSize();
150151
const char* contents = (const char *)const_cast<void *>(blob->RawContent());
151152

152-
Buffer* buffer = Buffer::New(const_cast<char *>(contents), strlen(contents));
153+
int bufferLength = strlen(contents);
154+
Buffer* buffer = Buffer::New(const_cast<char *>(contents), bufferLength);
155+
156+
Local<Object> fastBuffer;
157+
MAKE_FAST_BUFFER(buffer, fastBuffer);
153158

154-
return scope.Close( buffer->handle_ );
159+
return scope.Close( fastBuffer );
155160
}
156161

157162
Handle<Value> GitBlob::RawSize(const Arguments& args) {

wscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os, shutil, platform
44
from os import system
55
from os.path import exists, abspath
66

7-
VERSION = '0.0.4'
7+
VERSION = '0.0.5'
88
APPNAME = 'nodegit'
99
srcdir = '.'
1010
blddir = 'build'

0 commit comments

Comments
 (0)