Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
fs: getOption to populate passed in default values#11630
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.
Conversation
fhalde commented Mar 1, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
In fs.js, the getOption can be improved to populate the option object with the passed in defaultOptions if the default options are not there in the original option object. This way we don't have to do options.flag || 'w' etc.
sam-github commented Mar 1, 2017
This PR would be easier to understand if the description contained some example code that does not work as expected before your change (with a description of what you consider expected). |
fhalde commented Mar 1, 2017
@sam-github There is nothing that is working unexpectedly. I just felt we are duplicating the work of checking if default values exists or not in the options. For e.g. fs.writeFile=function(file,options,cb){options=getOptions(options,{flag: 'w'});/* later somewhere */flags=options.flags||'w'/* could have just been the below had getOptions populated the default values if not exist */flags=options.flags} |
fhalde commented Mar 1, 2017
Updated the description to explain what this PR would lead to |
jasnell commented Mar 15, 2017
@nodejs/collaborators ... thoughts? |
jasnell commented Mar 15, 2017
| if(options.encoding!=='buffer') | ||
| assertEncoding(options.encoding); | ||
| returnoptions; | ||
| returnObject.assign({},defaultOptions,options); |
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.
Have you benchmarked this? I thought Object.assign() was still slow?
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.
never done a benchmark. do we have any existing ones to compare it with? or any suggestions how to do a benchmark? Thanks
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 was suggested to use util.extend, would it be faster ?
mscdexMar 15, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, util._extend() would probably be a better choice, at least in core. Object.assign() is probably fine for tests and non-runtime stuff.
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.
Related discussion: #7165 (comment)
rmg commented Mar 15, 2017
Why are the tests changed to use |
fhalde commented Mar 15, 2017
@rmg I can recall that |
rmg commented Mar 15, 2017
Doh! I should have caught that 😊 |
fhalde commented Mar 16, 2017
@rmg it shouldn't be a problem though right ? I mean was there a reason why in the tests the properties were put in the prototype ? |
rmg commented Mar 20, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@fhalde after some digging, it seems those tests are intentionally written to use edit forgot to add, this is actually what the |
fhalde commented Mar 21, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@rmg |
rmg commented Mar 23, 2017
@fhalde it seems like this might end up being a lost cause then, since a solution that supports prototypes might end up being more complicated than just leaving things as they are :-( |
fhalde commented Mar 26, 2017
Agree too. I'll close it ? @rmg |
rmg commented Mar 27, 2017
@fhalde agreed, may as well close this. FWIW, I liked the idea behind the change. |
jasnell commented Mar 27, 2017
Closing based on the discussion. |
In
fs.js, thegetOptioncan be improved to populate the option object with the passed in defaultOptions if the default options are not there in the original option object. This way we don't have to dooptions.flag || 'w'etc.For example in the
fs.writeFileSimilar patterns are present in few more parts of the
fsmoduleChecklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
fs, test