Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
Feature/faster crypto#664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c319fd138cf628fcbf80c077bc997c05132File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,13 +5,60 @@ | ||
| #include "v8.h" | ||
| #include "node.h" | ||
| #include "env.h" | ||
| #include "env-inl.h" | ||
| namespace node { | ||
| extern int WRITE_UTF8_FLAGS; | ||
| class StringBytes { | ||
| public: | ||
| class InlineDecoder { | ||
| public: | ||
| explicit InlineDecoder(Environment* env) : env_(env), out_(nullptr) { | ||
| } | ||
| ~InlineDecoder() { | ||
| if (out_ != out_st_) | ||
| delete[] out_; | ||
| out_ = nullptr; | ||
| } | ||
| inline bool Decode(v8::Handle<v8::String> string, | ||
| v8::Handle<v8::Value> encoding, | ||
| enum encoding _default) { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a tiny nit and I realize you copied the convention from src/node.cc, but MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. | ||
| enum encoding enc = ParseEncoding(env_->isolate(), encoding, _default); | ||
| if (!StringBytes::IsValidString(env_->isolate(), string, enc)) { | ||
| env_->ThrowTypeError("Bad input string"); | ||
| return false; | ||
| } | ||
| size_t buflen = StringBytes::StorageSize(env_->isolate(), string, enc); | ||
| if (buflen > sizeof(out_st_)) | ||
| out_ = new char[buflen]; | ||
| else | ||
| out_ = out_st_; | ||
| size_ = StringBytes::Write(env_->isolate(), | ||
| out_, | ||
| buflen, | ||
| string, | ||
| enc); | ||
| return true; | ||
| } | ||
| inline const char* out() const { return out_; } | ||
| inline size_t size() const { return size_; } | ||
| private: | ||
| static const int kStorageSize = 1024; | ||
| Environment* env_; | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe pass the env as an argument to Decode()? It's not a big win but it reduces the stack footprint by a word. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. | ||
| char out_st_[kStorageSize]; | ||
| char* out_; | ||
| size_t size_; | ||
| }; | ||
| // Does the string match the encoding? Quick but non-exhaustive. | ||
| // Example: a HEX string must have a length that's a multiple of two. | ||
| // FIXME(bnoordhuis) IsMaybeValidString()? Naming things is hard... | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably do a little better still by also passing
encoding->length(). Then you can filter on length first before you start comparing bytes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, wouldn't it be cheaper to do the comparison in JS and just pass integers to C++ land? I suspect that the biggest overhead is from the new[]/delete[] calls, not the string comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm +1 for JS-land thing, but for now - let's do it the way it is.
encoding->length()doesn't seem to be improving situation much on my benchmarks.