summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-07-12 14:48:23 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-07-12 14:48:23 +0900
commitadf453a584a67d788ca2a1ea30444fda9bb595a8 (patch)
tree808d7e6fbd59e2253f192c9b748706463bb8973e /src
parent059d707e3a2f5e3e528ec7249090b17a3c7de4d9 (diff)
downloadmruby-adf453a584a67d788ca2a1ea30444fda9bb595a8.tar.gz
mruby-adf453a584a67d788ca2a1ea30444fda9bb595a8.zip
Add "*!" argument specifier to avoid stack copying.
Diffstat (limited to 'src')
-rw-r--r--src/class.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/class.c b/src/class.c
index 99ad14d81..9b8c3ce34 100644
--- a/src/class.c
+++ b/src/class.c
@@ -896,15 +896,25 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
{
mrb_value **var;
mrb_int *pl;
+ mrb_bool nocopy = FALSE;
+ if (*format == '!') {
+ format++;
+ nocopy = TRUE;
+ }
var = va_arg(ap, mrb_value**);
pl = va_arg(ap, mrb_int*);
if (argc > i) {
*pl = argc-i;
if (*pl > 0) {
- mrb_value args = mrb_ary_new_from_values(mrb, *pl, ARGV+arg_i);
- RARRAY(args)->c = NULL;
- *var = (mrb_value*)RARRAY_PTR(args);
+ if (nocopy) {
+ *var = ARGV+arg_i;
+ }
+ else {
+ mrb_value args = mrb_ary_new_from_values(mrb, *pl, ARGV+arg_i);
+ RARRAY(args)->c = NULL;
+ *var = (mrb_value*)RARRAY_PTR(args);
+ }
}
i = argc;
arg_i += *pl;