forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add string class that uses ExternalAsciiStringResource.
Change the natives to use this class instead of creating completely new strings. Reduces memory usage by about 1 MB.
- Loading branch information
Showing
8 changed files
with
74 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "node_string.h" | ||
|
||
namespace node { | ||
|
||
using namespace v8; | ||
|
||
Handle<String> ImmutableAsciiSource::CreateFromLiteral( | ||
const char *string_literal, | ||
size_t length) { | ||
HandleScope scope; | ||
|
||
Local<String> ret = String::NewExternal(new ImmutableAsciiSource( | ||
string_literal, | ||
length)); | ||
return scope.Close(ret); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef SRC_NODE_STRING_H_ | ||
#define SRC_NODE_STRING_H_ | ||
|
||
#include <v8.h> | ||
|
||
namespace node { | ||
|
||
#define IMMUTABLE_STRING(string_literal) \ | ||
::node::ImmutableAsciiSource::CreateFromLiteral( \ | ||
string_literal "", sizeof(string_literal) - 1) | ||
#define BUILTIN_ASCII_ARRAY(array, len) \ | ||
::node::ImmutableAsciiSource::CreateFromLiteral(array, len) | ||
|
||
class ImmutableAsciiSource : public v8::String::ExternalAsciiStringResource { | ||
public: | ||
static v8::Handle<v8::String> CreateFromLiteral(const char *string_literal, | ||
size_t length); | ||
|
||
ImmutableAsciiSource(const char *src, size_t src_len) | ||
: buffer_(src), | ||
buf_len_(src_len) { | ||
} | ||
|
||
~ImmutableAsciiSource() { | ||
} | ||
|
||
const char *data() const { | ||
return buffer_; | ||
} | ||
|
||
size_t length() const { | ||
return buf_len_; | ||
} | ||
|
||
private: | ||
const char *buffer_; | ||
size_t buf_len_; | ||
}; | ||
|
||
} // namespace node | ||
|
||
#endif // SRC_NODE_STRING_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters