예제 #1
0
  private void propagateFrozen(Object object, DynamicObject singletonClass) {
    assert RubyGuards.isRubyClass(singletonClass);

    if (isFrozenNode == null) {
      CompilerDirectives.transferToInterpreterAndInvalidate();
      isFrozenNode = insert(IsFrozenNodeGen.create(getContext(), getSourceSection(), null));
      freezeNode = insert(FreezeNodeGen.create(getContext(), getSourceSection(), null));
    }

    if (isFrozenNode.executeIsFrozen(object)) {
      freezeNode.executeFreeze(singletonClass);
    }
  }
예제 #2
0
    @ExplodeLoop
    @Override
    public Object execute(VirtualFrame frame) {
      final Object[] store = PackedArrayStrategy.createStore();

      int size = 0;

      initializers:
      for (int n = 0; n < keyValues.length / 2; n++) {
        Object key = keyValues[n * 2].execute(frame);

        if (stringKeyProfile.profile(RubyGuards.isRubyString(key))) {
          if (isFrozenNode == null) {
            CompilerDirectives.transferToInterpreter();
            isFrozenNode = insert(IsFrozenNodeGen.create(getContext(), getSourceSection(), null));
          }

          if (!isFrozenNode.executeIsFrozen(key)) {
            key = freezeNode.call(frame, dupNode.call(frame, key, "dup", null), "freeze", null);
          }
        }

        final int hashed = hashNode.hash(frame, key);

        final Object value = keyValues[n * 2 + 1].execute(frame);

        for (int i = 0; i < n; i++) {
          if (i < size
              && hashed == PackedArrayStrategy.getHashed(store, i)
              && equalNode.callBoolean(
                  frame, key, "eql?", null, PackedArrayStrategy.getKey(store, i))) {
            PackedArrayStrategy.setKey(store, i, key);
            PackedArrayStrategy.setValue(store, i, value);
            continue initializers;
          }
        }

        PackedArrayStrategy.setHashedKeyValue(store, size, hashed, key, value);
        size++;
      }

      return HashNodes.createHash(getContext().getCoreLibrary().getHashClass(), store, size);
    }