Skip to content
Permalink
Browse files

Give full access with Attribute.get/set_value

The idea being that these methods are sufficiently low-level that they should
give direct raw access to the attribute.  Also slightly optimized it for the
most common case of an object with an Opaque representation.  Fixes R#2521
  • Loading branch information...
lizmat committed Dec 8, 2018
1 parent dd03014 commit a5411e4518ccdafe3ea187150ba9dfa4e42e8bdc
Showing with 14 additions and 25 deletions.
  1. +14 −25 src/core/Attribute.pm6
@@ -164,46 +164,35 @@ my class Attribute { # declared in BOOTSTRAP
# None by default.
}

method get_value(Mu $obj) {
method get_value(Mu $obj) is raw {
nqp::if(
nqp::iseq_i((my int $t = nqp::objprimspec($!type)),0),
nqp::getattr(nqp::decont($obj),$!package,$!name),
(my int $t = nqp::objprimspec($!type)),
nqp::if(
nqp::iseq_i($t,1),
nqp::p6box_i(nqp::getattr_i(nqp::decont($obj),$!package,$!name)),
nqp::getattr_i(nqp::decont($obj),$!package,$!name),
nqp::if(
nqp::iseq_i($t,2),
nqp::p6box_n(nqp::getattr_n(nqp::decont($obj),
$!package,$!name)),
nqp::if(
nqp::iseq_i($t,3),
nqp::p6box_s(nqp::getattr_s(nqp::decont($obj),
$!package,$!name))
)
nqp::getattr_n(nqp::decont($obj),$!package,$!name),
nqp::getattr_s(nqp::decont($obj),$!package,$!name) # assume 3
)
)
),
nqp::getattr(nqp::decont($obj),$!package,$!name)
)
}

method set_value(Mu $obj, Mu \value) {
method set_value(Mu $obj, Mu \value) is raw {
nqp::if(
nqp::iseq_i((my int $t = nqp::objprimspec($!type)),0),
nqp::bindattr(nqp::decont($obj),$!package,$!name,value),
(my int $t = nqp::objprimspec($!type)),
nqp::if(
nqp::iseq_i($t,1),
nqp::p6box_i(nqp::bindattr_i(nqp::decont($obj),
$!package,$!name,value)),
nqp::bindattr_i(nqp::decont($obj),$!package,$!name,value),
nqp::if(
nqp::iseq_i($t,2),
nqp::p6box_n(nqp::bindattr_n(nqp::decont($obj),
$!package,$!name,value)),
nqp::if(
nqp::iseq_i($t,3),
nqp::p6box_s(nqp::bindattr_s(nqp::decont($obj),
$!package,$!name,value))
)
nqp::bindattr_n(nqp::decont($obj),$!package,$!name,value),
nqp::bindattr_s(nqp::decont($obj),$!package,$!name,value)
)
)
),
nqp::bindattr(nqp::decont($obj),$!package,$!name,value)
)
}

0 comments on commit a5411e4

Please sign in to comment.
You can’t perform that action at this time.