Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add :view named parameter to KeySet.Set and KeyBag.Bag coercers
This is a test to see whether this makes sense or not: basically, whenever we coerce a KeySet to a Set, or a KeyBag to a Bag, and the :view parameter is specified, we create an object using the same underlying :elems hash. This prevents wasteful copying e.g. inside the (&) and other operators.
- Loading branch information
Showing
4 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| my class KeyBag does Baggy { | ||
|
|
||
| method Bag { Bag.new-fp(nqp::getattr(self, KeyBag, '%!elems').values) } | ||
| method Bag (:$view) { | ||
| if $view { | ||
| my $bag := nqp::create(Bag); | ||
| $bag.BUILD( :elems(nqp::getattr(self, KeyBag, '%!elems')) ); | ||
| $bag; | ||
| } | ||
| else { | ||
| Bag.new-fp(nqp::getattr(self, KeyBag, '%!elems').values); | ||
| } | ||
| } | ||
| method KeyBag { self } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,15 @@ | ||
| my class KeySet does Setty { | ||
|
|
||
| method Set { Set.new(self.keys) } | ||
| method Set (:$view) { | ||
| if $view { | ||
| my $set := nqp::create(Set); | ||
| $set.BUILD( :elems(nqp::getattr(self, KeySet, '%!elems')) ); | ||
| $set; | ||
| } | ||
| else { | ||
| Set.new(self.keys); | ||
| } | ||
| } | ||
|
|
||
| method KeySet { self } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters