-
-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This was rather more involved than just prefixing with BEGIN, as .bless does not appear to work at that point in the setting yet. And passing HLL Lists at that point, also doesn't work. So use more primitive means to create the Encoding::Builtin objects.
- Loading branch information
Showing
1 changed file
with
56 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
class Encoding::Builtin does Encoding { | ||
has Str $.name; | ||
has @.alternative-names; | ||
has $!alternative-names; | ||
|
||
method new() { | ||
X::Cannot::New.new(class => self.WHAT).throw | ||
} | ||
|
||
method alternative-names() { @!alternative-names } | ||
method SET-SELF(\name, \alternatives) { | ||
nqp::stmts( | ||
($!name := name), | ||
($!alternative-names := alternatives), | ||
self | ||
) | ||
} | ||
|
||
method alternative-names() { $!alternative-names } | ||
|
||
method decoder(*%options --> Encoding::Decoder) { | ||
Encoding::Decoder::Builtin.new($!name, |%options) | ||
|
@@ -35,27 +43,49 @@ class Encoding::Builtin does Encoding { | |
} | ||
} | ||
|
||
Encoding::Registry.register(Encoding::Builtin.bless( | ||
:name<utf8>, :alternative-names<utf-8> | ||
)); | ||
Encoding::Registry.register(Encoding::Builtin.bless( | ||
:name<utf8-c8>, :alternative-names<utf-8-c8> | ||
)); | ||
Encoding::Registry.register(Encoding::Builtin.bless( | ||
:name<ascii> | ||
)); | ||
Encoding::Registry.register(Encoding::Builtin.bless( | ||
:name<iso-8859-1>, :alternative-names< | ||
iso_8859-1:1987 iso_8859-1 iso-ir-100 latin1 latin-1 csisolatin1 | ||
l1 ibm819 cp819 | ||
> | ||
)); | ||
Encoding::Registry.register(Encoding::Builtin.bless( | ||
:name<windows-1252> | ||
)); | ||
Encoding::Registry.register(Encoding::Builtin.bless( | ||
:name<utf16>, :alternative-names<utf-16> | ||
)); | ||
Encoding::Registry.register(Encoding::Builtin.bless( | ||
:name<utf32>, :alternative-names<utf-32> | ||
)); | ||
Encoding::Registry.register( | ||
BEGIN nqp::create(Encoding::Builtin).SET-SELF( | ||
"utf8", nqp::list("utf-8") | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lizmat
Author
Contributor
|
||
) | ||
); | ||
Encoding::Registry.register( | ||
BEGIN nqp::create(Encoding::Builtin).SET-SELF( | ||
"utf8-c8", nqp::list("utf-8-c8") | ||
) | ||
); | ||
Encoding::Registry.register( | ||
BEGIN nqp::create(Encoding::Builtin).SET-SELF( | ||
"ascii", nqp::list | ||
) | ||
); | ||
Encoding::Registry.register( | ||
BEGIN nqp::create(Encoding::Builtin).SET-SELF( | ||
"iso-8859-1", | ||
nqp::list( | ||
"iso_8859-1:1987", | ||
"iso_8859-1", | ||
"iso-ir-100", | ||
"latin1", | ||
"latin-1", | ||
"csisolatin1:", | ||
"l1", | ||
"ibm819", | ||
"cp819" | ||
) | ||
) | ||
); | ||
Encoding::Registry.register( | ||
BEGIN nqp::create(Encoding::Builtin).SET-SELF( | ||
"windows-1252", nqp::list | ||
) | ||
); | ||
Encoding::Registry.register( | ||
BEGIN nqp::create(Encoding::Builtin).SET-SELF( | ||
"utf16", nqp::list("utf-16") | ||
) | ||
); | ||
Encoding::Registry.register( | ||
BEGIN nqp::create(Encoding::Builtin).SET-SELF( | ||
"utf32", nqp::list("utf-32") | ||
) | ||
); |
1 comment
on commit 79ce1a9
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.
Precompile, rather :-)
Why the
nqp::list
? The first thing that's going to happen is the registry will callalternative-names
, which will then on-demand wrap it into a Perl 6 levelList
, causing a runtime allocation. Whereas if that was unchanged then it'd just make aList
at compile time, and not having to do the runtime wrapping.