org.jruby.RubyHash.dupFast()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(68)

本文整理了Java中org.jruby.RubyHash.dupFast方法的一些代码示例,展示了RubyHash.dupFast的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RubyHash.dupFast方法的具体详情如下:
包路径:org.jruby.RubyHash
类名称:RubyHash
方法名:dupFast

RubyHash.dupFast介绍

[英]A lightweight dup for internal use that does not dispatch to initialize_copy nor rehash the keys. Intended for use in dup'ing keyword args for processing.
[中]一种内部使用的轻量级dup,不发送以初始化、复制或重新缓存密钥。用于复制关键字参数以进行处理。

代码示例

代码示例来源:origin: org.jruby/jruby-core

@JIT
public static RubyHash dupKwargsHashAndPopulateFromArray(ThreadContext context, RubyHash dupHash, IRubyObject[] pairs) {
  Ruby runtime = context.runtime;
  RubyHash hash = dupHash.dupFast(context);
  for (int i = 0; i < pairs.length;) {
    hash.fastASet(runtime, pairs[i++], pairs[i++], true);
  }
  return hash;
}

代码示例来源:origin: org.jruby/jruby-complete

@JIT
public static RubyHash dupKwargsHashAndPopulateFromArray(ThreadContext context, RubyHash dupHash, IRubyObject[] pairs) {
  Ruby runtime = context.runtime;
  RubyHash hash = dupHash.dupFast(context);
  for (int i = 0; i < pairs.length;) {
    hash.fastASet(runtime, pairs[i++], pairs[i++], true);
  }
  return hash;
}

代码示例来源:origin: org.jruby/jruby-complete

@JIT
public static IRubyObject[] frobnicateKwargsArgument(ThreadContext context, IRubyObject[] args, int requiredArgsCount) {
  // No kwarg because required args slurp them up.
  int length = args.length;
  if (length <= requiredArgsCount) return args;
  final IRubyObject maybeKwargs = toHash(context, args[length - 1]);
  if (maybeKwargs != null) {
    if (maybeKwargs.isNil()) { // nil on to_hash is supposed to keep itself as real value so we need to make kwargs hash
      return ArraySupport.newCopy(args, RubyHash.newSmallHash(context.runtime));
    }
    RubyHash kwargs = (RubyHash) maybeKwargs;
    if (kwargs.allSymbols()) {
      args[length - 1] = kwargs.dupFast(context);
    } else {
      args = homogenizeKwargs(context, args, kwargs);
    }
  }
  return args;
}

代码示例来源:origin: org.jruby/jruby-core

@Override
public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
  Ruby runtime = context.runtime;
  RubyHash hash;
  KeyValuePair<Operand, Operand>[] pairs = this.pairs;
  int index = 0;
  if (isKWArgsHash && pairs[0].getKey().equals(Symbol.KW_REST_ARG_DUMMY)) {
    // Dup the rest args hash and use that as the basis for inserting the non-rest args
    hash = ((RubyHash) pairs[0].getValue().retrieve(context, self, currScope, currDynScope, temp)).dupFast(context);
    // Skip the first pair
    index++;
  } else {
    hash = RubyHash.newHash(runtime);
  }
  for (int i = index; i < pairs.length; i++) {
    KeyValuePair<Operand, Operand> pair = pairs[i];
    IRubyObject key = (IRubyObject) pair.getKey().retrieve(context, self, currScope, currDynScope, temp);
    IRubyObject value = (IRubyObject) pair.getValue().retrieve(context, self, currScope, currDynScope, temp);
    hash.fastASetCheckString(runtime, key, value);
  }
  return hash;
}

代码示例来源:origin: org.jruby/jruby-complete

@Override
public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
  Ruby runtime = context.runtime;
  RubyHash hash;
  KeyValuePair<Operand, Operand>[] pairs = this.pairs;
  int index = 0;
  if (isKWArgsHash && pairs[0].getKey().equals(Symbol.KW_REST_ARG_DUMMY)) {
    // Dup the rest args hash and use that as the basis for inserting the non-rest args
    hash = ((RubyHash) pairs[0].getValue().retrieve(context, self, currScope, currDynScope, temp)).dupFast(context);
    // Skip the first pair
    index++;
  } else {
    hash = RubyHash.newHash(runtime);
  }
  for (int i = index; i < pairs.length; i++) {
    KeyValuePair<Operand, Operand> pair = pairs[i];
    IRubyObject key = (IRubyObject) pair.getKey().retrieve(context, self, currScope, currDynScope, temp);
    IRubyObject value = (IRubyObject) pair.getValue().retrieve(context, self, currScope, currDynScope, temp);
    hash.fastASetCheckString(runtime, key, value);
  }
  return hash;
}

代码示例来源:origin: org.jruby/jruby-core

@JIT
public static IRubyObject[] frobnicateKwargsArgument(ThreadContext context, IRubyObject[] args, int requiredArgsCount) {
  // No kwarg because required args slurp them up.
  int length = args.length;
  if (length <= requiredArgsCount) return args;
  final IRubyObject maybeKwargs = toHash(context, args[length - 1]);
  if (maybeKwargs != null) {
    if (maybeKwargs.isNil()) { // nil on to_hash is supposed to keep itself as real value so we need to make kwargs hash
      return ArraySupport.newCopy(args, RubyHash.newSmallHash(context.runtime));
    }
    RubyHash kwargs = (RubyHash) maybeKwargs;
    if (kwargs.allSymbols()) {
      args[length - 1] = kwargs.dupFast(context);
    } else {
      args = homogenizeKwargs(context, args, kwargs);
    }
  }
  return args;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

protected void assignKwargs(RubyHash keyValues, Ruby runtime, ThreadContext context, DynamicScope scope, IRubyObject self) {
  if (keyValues != null) {
    if (keywords != null) {
      keyValues = keyValues.dupFast(context);
      List<Node> keywordNodes = keywords.childNodes();
      for (int i = 0; i < keywordNodes.size(); i++) {

代码示例来源:origin: org.jruby/jruby-complete

optHash = opt == context.nil ? RubyHash.newHash(runtime) : ((RubyHash) opt).dupFast(context);

代码示例来源:origin: org.jruby/jruby-core

optHash = opt == context.nil ? RubyHash.newHash(runtime) : ((RubyHash) opt).dupFast(context);

相关文章

微信公众号

最新文章

更多

RubyHash类方法