summaryrefslogtreecommitdiff
path: root/src/node_string.h
diff options
context:
space:
mode:
authorTom Hughes <tom.hughes@palm.com>2011-03-08 00:00:51 -0600
committerRyan Dahl <ry@tinyclouds.org>2011-03-08 13:56:41 -0800
commit74954ce7d8b4b734302d295d0c816f04a694254e (patch)
tree75b61a90a05d4950c89e78a1a362cb4df4bf33f5 /src/node_string.h
parent81d3de7e6db6abe36ac907d8f0fa6dfc01f7bbcd (diff)
downloadnode-new-74954ce7d8b4b734302d295d0c816f04a694254e.tar.gz
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.
Diffstat (limited to 'src/node_string.h')
-rw-r--r--src/node_string.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/node_string.h b/src/node_string.h
new file mode 100644
index 0000000000..1854cc2933
--- /dev/null
+++ b/src/node_string.h
@@ -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_