-
Notifications
You must be signed in to change notification settings - Fork 275
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
Add methods from List
/Map
to Listing
/Mapping
#683
base: main
Are you sure you want to change the base?
Conversation
var keys = getAllKeys(); | ||
var builder = new VmObjectBuilder(keys.getLength()); | ||
for (var key : keys) { | ||
var member = VmUtils.readMember(this, key); |
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.
var member = VmUtils.readMember(this, key); | |
var value = VmUtils.readMember(this, key); |
public VmDynamic toDynamic() { | ||
var keys = getAllKeys(); | ||
var builder = new VmObjectBuilder(keys.getLength()); | ||
for (var key : keys) { |
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.
How about using self.forceAndIterateMemberValues()
here? This should be much more efficient than calling readMember()
repeatedly because it iterates the amend hierarchy only once.
Zooming out, how about returning a Dynamic
whose members delegate to the mapping? This would avoid the need to force the mapping, which seems desirable.
Same comment applies to other similar methods.
|
||
/// Converts this mapping to a [Map]. | ||
external function toMap(): Map<Key, Value> | ||
|
||
/// Converts this mapping to a [Dynamic] object. | ||
external function toDynamic(): Dynamic |
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.
How about documenting that late binding and Mapping.default
are not preserved?
"Returns a Dynamic that delegates to this mapping" would be a clear explanation of a good implementation.
@@ -220,6 +220,11 @@ public VmCollection.Builder<VmList> builder() { | |||
return new Builder(); | |||
} | |||
|
|||
@TruffleBoundary | |||
public static VmCollection.Builder<VmList> newBuilder() { |
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.
Existing code uses VmList.EMPTY.builder()
instead.
Methods that "project out" of the type can be added to
Listing
andMapping
to avoid having to usetoList()
/toMap()
. Methods that result in aListing
, resp.Mapping
, are not included for performance and (lazy) semantics reasons, but methods likecontains
etc. can be defined straightforwardly.