Permalink
Browse files

Avoiding unnecessary ToString() calls

String::Utf8Value and String::AsciiValue constructors take Handle<Value>
So no need to convert to Handle<String>
  • Loading branch information...
1 parent e1199fa commit 249c3c165ab3b93e1bd0a05668d81b289b8d4ccf ssuda committed with bnoordhuis Mar 21, 2012
Showing with 62 additions and 62 deletions.
  1. +3 −3 src/cares_wrap.cc
  2. +1 −1 src/fs_event_wrap.cc
  3. +9 −9 src/node.cc
  4. +1 −1 src/node_buffer.cc
  5. +15 −15 src/node_crypto.cc
  6. +2 −2 src/node_dtrace.cc
  7. +18 −18 src/node_file.cc
  8. +1 −1 src/node_stat_watcher.cc
  9. +2 −2 src/pipe_wrap.cc
  10. +2 −2 src/process_wrap.cc
  11. +4 −4 src/tcp_wrap.cc
  12. +4 −4 src/udp_wrap.cc
View
@@ -555,7 +555,7 @@ static Handle<Value> Query(const Arguments& args) {
// object reference, causing wrap->GetObject() to return undefined.
Local<Object> object = Local<Object>::New(wrap->GetObject());
- String::Utf8Value name(args[0]->ToString());
+ String::Utf8Value name(args[0]);
int r = wrap->Send(*name);
if (r) {
@@ -584,7 +584,7 @@ static Handle<Value> QueryWithFamily(const Arguments& args) {
// object reference, causing wrap->GetObject() to return undefined.
Local<Object> object = Local<Object>::New(wrap->GetObject());
- String::Utf8Value name(args[0]->ToString());
+ String::Utf8Value name(args[0]);
int family = args[1]->Int32Value();
int r = wrap->Send(*name, family);
@@ -688,7 +688,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
static Handle<Value> GetAddrInfo(const Arguments& args) {
HandleScope scope;
- String::Utf8Value hostname(args[0]->ToString());
+ String::Utf8Value hostname(args[0]);
int fam = AF_UNSPEC;
if (args[1]->IsInt32()) {
View
@@ -107,7 +107,7 @@ Handle<Value> FSEventWrap::Start(const Arguments& args) {
return ThrowException(Exception::TypeError(String::New("Bad arguments")));
}
- String::Utf8Value path(args[0]->ToString());
+ String::Utf8Value path(args[0]);
int r = uv_fs_event_init(uv_default_loop(), &wrap->handle_, *path, OnEvent, 0);
if (r == 0) {
View
@@ -1020,7 +1020,7 @@ enum encoding ParseEncoding(Handle<Value> encoding_v, enum encoding _default) {
if (!encoding_v->IsString()) return _default;
- String::Utf8Value encoding(encoding_v->ToString());
+ String::Utf8Value encoding(encoding_v);
if (strcasecmp(*encoding, "utf8") == 0) {
return UTF8;
@@ -1231,8 +1231,8 @@ static void ReportException(TryCatch &try_catch, bool show_line) {
fprintf(stderr, "%s: ", *name);
}
- String::Utf8Value msg(!isErrorObject ? er->ToString()
- : er->ToObject()->Get(String::New("message"))->ToString());
+ String::Utf8Value msg(!isErrorObject ? er
+ : er->ToObject()->Get(String::New("message")));
fprintf(stderr, "%s\n", *msg);
}
@@ -1273,7 +1273,7 @@ static Handle<Value> Chdir(const Arguments& args) {
return ThrowException(Exception::Error(String::New("Bad argument.")));
}
- String::Utf8Value path(args[0]->ToString());
+ String::Utf8Value path(args[0]);
uv_err_t r = uv_chdir(*path);
@@ -1373,7 +1373,7 @@ static Handle<Value> SetGid(const Arguments& args) {
if (args[0]->IsNumber()) {
gid = args[0]->Int32Value();
} else if (args[0]->IsString()) {
- String::Utf8Value grpnam(args[0]->ToString());
+ String::Utf8Value grpnam(args[0]);
struct group grp, *grpp = NULL;
int err;
@@ -1413,7 +1413,7 @@ static Handle<Value> SetUid(const Arguments& args) {
if (args[0]->IsNumber()) {
uid = args[0]->Int32Value();
} else if (args[0]->IsString()) {
- String::Utf8Value pwnam(args[0]->ToString());
+ String::Utf8Value pwnam(args[0]);
struct passwd pwd, *pwdp = NULL;
int err;
@@ -1620,7 +1620,7 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
return ThrowException(exception);
}
- String::Utf8Value filename(args[0]->ToString()); // Cast
+ String::Utf8Value filename(args[0]); // Cast
Local<Object> target = args[1]->ToObject(); // Cast
err = uv_dlopen(*filename, &lib);
@@ -1641,7 +1641,7 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
return ThrowException(exception);
}
- String::Utf8Value path(args[0]->ToString());
+ String::Utf8Value path(args[0]);
base = *path;
/* Find the shared library filename within the full path. */
@@ -1855,7 +1855,7 @@ static void ProcessTitleSetter(Local<String> property,
Local<Value> value,
const AccessorInfo& info) {
HandleScope scope;
- String::Utf8Value title(value->ToString());
+ String::Utf8Value title(value);
// TODO: protect with a lock
uv_set_process_title(*title);
}
View
@@ -589,7 +589,7 @@ Handle<Value> Buffer::Base64Write(const Arguments &args) {
"Argument must be a string")));
}
- String::AsciiValue s(args[0]->ToString());
+ String::AsciiValue s(args[0]);
size_t offset = args[1]->Int32Value();
size_t max_length = args[2]->IsUndefined() ? buffer->length_ - offset
: args[2]->Uint32Value();
View
@@ -170,7 +170,7 @@ Handle<Value> SecureContext::Init(const Arguments& args) {
OPENSSL_CONST SSL_METHOD *method = SSLv23_method();
if (args.Length() == 1 && args[0]->IsString()) {
- String::Utf8Value sslmethod(args[0]->ToString());
+ String::Utf8Value sslmethod(args[0]);
if (strcmp(*sslmethod, "SSLv2_method") == 0) {
#ifndef OPENSSL_NO_SSL2
@@ -234,7 +234,7 @@ static BIO* LoadBIO (Handle<Value> v) {
int r = -1;
if (v->IsString()) {
- String::Utf8Value s(v->ToString());
+ String::Utf8Value s(v);
r = BIO_write(bio, *s, s.length());
} else if (Buffer::HasInstance(v)) {
Local<Object> buffer_obj = v->ToObject();
@@ -287,7 +287,7 @@ Handle<Value> SecureContext::SetKey(const Arguments& args) {
BIO *bio = LoadBIO(args[0]);
if (!bio) return False();
- String::Utf8Value passphrase(args[1]->ToString());
+ String::Utf8Value passphrase(args[1]);
EVP_PKEY* key = PEM_read_bio_PrivateKey(bio, NULL, NULL,
len == 1 ? NULL : *passphrase);
@@ -514,7 +514,7 @@ Handle<Value> SecureContext::SetCiphers(const Arguments& args) {
return ThrowException(Exception::TypeError(String::New("Bad parameter")));
}
- String::Utf8Value ciphers(args[0]->ToString());
+ String::Utf8Value ciphers(args[0]);
SSL_CTX_set_cipher_list(sc->ctx_, *ciphers);
return True();
@@ -545,7 +545,7 @@ Handle<Value> SecureContext::SetSessionIdContext(const Arguments& args) {
return ThrowException(Exception::TypeError(String::New("Bad parameter")));
}
- String::Utf8Value sessionIdContext(args[0]->ToString());
+ String::Utf8Value sessionIdContext(args[0]);
const unsigned char* sid_ctx = (const unsigned char*) *sessionIdContext;
unsigned int sid_ctx_len = sessionIdContext.length();
@@ -930,7 +930,7 @@ Handle<Value> Connection::New(const Arguments& args) {
if (is_server) {
SSL_CTX_set_tlsext_servername_callback(sc->ctx_, SelectSNIContextCallback_);
} else {
- String::Utf8Value servername(args[2]->ToString());
+ String::Utf8Value servername(args[2]);
SSL_set_tlsext_host_name(p->ssl_, *servername);
}
#endif
@@ -2016,7 +2016,7 @@ class Cipher : public ObjectWrap {
ssize_t key_written = DecodeWrite(key_buf, key_buf_len, args[1], BINARY);
assert(key_written == key_buf_len);
- String::Utf8Value cipherType(args[0]->ToString());
+ String::Utf8Value cipherType(args[0]);
bool r = cipher->CipherInit(*cipherType, key_buf, key_buf_len);
@@ -2066,7 +2066,7 @@ class Cipher : public ObjectWrap {
ssize_t iv_written = DecodeWrite(iv_buf, iv_len, args[2], BINARY);
assert(iv_written == iv_len);
- String::Utf8Value cipherType(args[0]->ToString());
+ String::Utf8Value cipherType(args[0]);
bool r = cipher->CipherInitIv(*cipherType, key_buf,key_len,iv_buf,iv_len);
@@ -2429,7 +2429,7 @@ class Decipher : public ObjectWrap {
ssize_t key_written = DecodeWrite(key_buf, key_len, args[1], BINARY);
assert(key_written == key_len);
- String::Utf8Value cipherType(args[0]->ToString());
+ String::Utf8Value cipherType(args[0]);
bool r = cipher->DecipherInit(*cipherType, key_buf,key_len);
@@ -2479,7 +2479,7 @@ class Decipher : public ObjectWrap {
ssize_t iv_written = DecodeWrite(iv_buf, iv_len, args[2], BINARY);
assert(iv_written == iv_len);
- String::Utf8Value cipherType(args[0]->ToString());
+ String::Utf8Value cipherType(args[0]);
bool r = cipher->DecipherInitIv(*cipherType, key_buf,key_len,iv_buf,iv_len);
@@ -2782,7 +2782,7 @@ class Hmac : public ObjectWrap {
return ThrowException(exception);
}
- String::Utf8Value hashType(args[0]->ToString());
+ String::Utf8Value hashType(args[0]);
bool r;
@@ -2946,7 +2946,7 @@ class Hash : public ObjectWrap {
"Must give hashtype string as argument")));
}
- String::Utf8Value hashType(args[0]->ToString());
+ String::Utf8Value hashType(args[0]);
Hash *hash = new Hash();
if (!hash->HashInit(*hashType)) {
@@ -3139,7 +3139,7 @@ class Sign : public ObjectWrap {
"Must give signtype string as argument")));
}
- String::Utf8Value signType(args[0]->ToString());
+ String::Utf8Value signType(args[0]);
bool r = sign->SignInit(*signType);
@@ -3390,7 +3390,7 @@ class Verify : public ObjectWrap {
"Must give verifytype string as argument")));
}
- String::Utf8Value verifyType(args[0]->ToString());
+ String::Utf8Value verifyType(args[0]);
bool r = verify->VerifyInit(*verifyType);
@@ -3589,7 +3589,7 @@ class DiffieHellman : public ObjectWrap {
String::New("No group name given")));
}
- String::Utf8Value group_name(args[0]->ToString());
+ String::Utf8Value group_name(args[0]);
modp_group* it = modp_groups;
View
@@ -54,7 +54,7 @@ using namespace v8;
return (ThrowException(Exception::Error(String::New("expected " \
"object for " #obj " to contain string member " #member)))); \
} \
- String::Utf8Value _##member(obj->Get(String::New(#member))->ToString()); \
+ String::Utf8Value _##member(obj->Get(String::New(#member))); \
if ((*(const char **)valp = *_##member) == NULL) \
*(const char **)valp = "<unknown>";
@@ -203,7 +203,7 @@ Handle<Value> DTRACE_HTTP_SERVER_REQUEST(const Arguments& args) {
"object for request to contain string member headers"))));
Local<Value> strfwdfor = headers->Get(String::New("x-forwarded-for"));
- String::Utf8Value fwdfor(strfwdfor->ToString());
+ String::Utf8Value fwdfor(strfwdfor);
if (!strfwdfor->IsString() || (req.forwardedFor = *fwdfor) == NULL)
req.forwardedFor = const_cast<char*>("");
Oops, something went wrong.

0 comments on commit 249c3c1

Please sign in to comment.