WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED WONTFIX
177892
JSC: use default_construct_at
https://bugs.webkit.org/show_bug.cgi?id=177892
Summary
JSC: use default_construct_at
JF Bastien
Reported
2017-10-04 12:55:06 PDT
I added default_construct_at to StdLibExtra in #177473 because some code was otherwise hard to read. I wanted to see how it would feel in other parts of the code, and whether it was a widespread thing that we'd use, so I grep'd for a few places in JSC where I could use it, and did so! I'm thinking about proposing this for C++20, so getting a feel for it seems useful, and in this case causes very little churn.
Attachments
patch
(4.44 KB, patch)
2017-10-04 12:56 PDT
,
JF Bastien
no flags
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
JF Bastien
Comment 1
2017-10-04 12:56:43 PDT
Created
attachment 322707
[details]
patch Does it look nicer? More understandable?
JF Bastien
Comment 2
2017-10-04 12:57:36 PDT
Forgot to say: an easy way to grep for likely uses is: git grep "new (" ./Source/JavaScriptCore/ | grep -v NotNull | grep "()"
Saam Barati
Comment 3
2017-10-04 13:01:50 PDT
I vote for default_construct_at => construct_at construct_at should just take variadic parameters it does perfect forwarding on. "Default" flows naturally out of that, e.g, no arguments passed.
Alexey Proskuryakov
Comment 4
2017-10-04 16:29:59 PDT
Comment on
attachment 322707
[details]
patch View in context:
https://bugs.webkit.org/attachment.cgi?id=322707&action=review
> Source/JavaScriptCore/ChangeLog:8 > + It makes code cleaner.
I know how to read placement new, but I would definitely need to look up what default_construct_at or construct_at were. In general, it seems undesirable to use 1:1 replacements for language constructs, as that adds barriers to entry.
> Source/JavaScriptCore/yarr/YarrInterpreter.cpp:91 > - return new (allocatorPool->alloc(size)) DisjunctionContext(); > + return &default_construct_at(static_cast<DisjunctionContext*>(allocatorPool->alloc(size)));
This in particular seems harder to read than before.
Saam Barati
Comment 5
2017-10-04 16:38:14 PDT
(In reply to Alexey Proskuryakov from
comment #4
)
> Comment on
attachment 322707
[details]
> patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=322707&action=review
> > > Source/JavaScriptCore/ChangeLog:8 > > + It makes code cleaner. > > I know how to read placement new, but I would definitely need to look up > what default_construct_at or construct_at were. > > In general, it seems undesirable to use 1:1 replacements for language > constructs, as that adds barriers to entry. > > > Source/JavaScriptCore/yarr/YarrInterpreter.cpp:91 > > - return new (allocatorPool->alloc(size)) DisjunctionContext(); > > + return &default_construct_at(static_cast<DisjunctionContext*>(allocatorPool->alloc(size))); > > This in particular seems harder to read than before.
I agree. I much prefer placement new.
JF Bastien
Comment 6
2017-10-19 21:22:27 PDT
Agreed with Saam's suggestion, can forward things. Code such as this is definitely harder to write as well as read: new (&container.get()[i]) std::remove_reference_t<decltype(*container.get())>(); That's the original inspiration for the initial proposal. That being said it's one place, so I don't really care.
Daniel Bates
Comment 7
2018-03-28 23:40:50 PDT
Comment on
attachment 322707
[details]
patch Clearing r and cq flags to get this patch out of these queues.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug