Skip to content

Commit

Permalink
src: general C++ cleanup in node_url.cc
Browse files Browse the repository at this point in the history
- Merge `domain` and `opaque` storage in URL parser:

  This just simplifies the code a bit, having multiple fields
  in an union with the same type is usually just overhead.

- Add move variant of `URLHost::ToString()`:

  This helps avoid unnecessary string copy operations, especially
  since we control the lifetime of `URLHost` objects pretty well.

- Use const refs in node_url.cc where appropriate

- Remove or reduce overly generous `.reserve()` calls:

  These would otherwise keep a lot of unused memory lying around.

- Return return values instead of unnecessary pointer arguments

- Use more common/expressive variable names

- Avoid macro use, reduce number of unnecessary JS strings:

  There’s no reason for `GET`, `GET_AND_SET` and `UTF8STRING` to be
  macros. Also, `GET` would previously create a JS string instance
  for each single call, even though the strings it was called
  with were compile-time constants.

- Avoid unnecessary JS casts when the type of a value is known

- Avoid (commonly unnecessary) copy for whitespace stripping

PR-URL: #19598
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
  • Loading branch information
addaleax committed Mar 30, 2018
1 parent b7cfd27 commit ae70e2b
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 151 deletions.
5 changes: 5 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ struct PackageConfig {
V(fingerprint_string, "fingerprint") \
V(fingerprint256_string, "fingerprint256") \
V(flags_string, "flags") \
V(fragment_string, "fragment") \
V(get_data_clone_error_string, "_getDataCloneError") \
V(get_shared_array_buffer_id_string, "_getSharedArrayBufferId") \
V(gid_string, "gid") \
V(handle_string, "handle") \
V(homedir_string, "homedir") \
V(host_string, "host") \
V(hostmaster_string, "hostmaster") \
V(ignore_string, "ignore") \
V(infoaccess_string, "infoAccess") \
Expand Down Expand Up @@ -226,6 +228,7 @@ struct PackageConfig {
V(order_string, "order") \
V(owner_string, "owner") \
V(parse_error_string, "Parse Error") \
V(password_string, "password") \
V(path_string, "path") \
V(pending_handle_string, "pendingHandle") \
V(pbkdf2_error_string, "PBKDF2 Error") \
Expand All @@ -239,6 +242,7 @@ struct PackageConfig {
V(produce_cached_data_string, "produceCachedData") \
V(promise_string, "promise") \
V(pubkey_string, "pubkey") \
V(query_string, "query") \
V(raw_string, "raw") \
V(read_host_object_string, "_readHostObject") \
V(readable_string, "readable") \
Expand All @@ -247,6 +251,7 @@ struct PackageConfig {
V(rename_string, "rename") \
V(replacement_string, "replacement") \
V(retry_string, "retry") \
V(scheme_string, "scheme") \
V(serial_string, "serial") \
V(scopeid_string, "scopeid") \
V(serial_number_string, "serialNumber") \
Expand Down

0 comments on commit ae70e2b

Please sign in to comment.