private static int makePropertyCount(ShapeImpl parent, PropertyMap propertyMap) { if (propertyMap.size() > parent.propertyMap.size()) { Property lastProperty = propertyMap.getLastProperty(); if (!lastProperty.isHidden()) { return parent.propertyCount + 1; } } return parent.propertyCount; }
public PropertyMap removeCopy(Property value) { Deque<Property> shelve = new ArrayDeque<>(); PropertyMap current = this; while (!current.isEmpty()) { if (current.getLastProperty().equals(value)) { PropertyMap newMap = current.getParentMap(); for (Property property : shelve) { newMap = newMap.putCopy(property); } return newMap; } else { shelve.push(current.getLastProperty()); current = current.getParentMap(); } } return this; }
/** @since 0.17 or earlier */ @Override public Property remove(final Object key) { throw unmodifiableException(); }
public PropertyMap putCopy(Property value) { assert !this.containsValue(value); return new PropertyMap(this, value); }
public PropertyMap getOwningMap(Property value) { PropertyMap current = this; while (!current.isEmpty()) { if (current.getLastProperty().equals(value)) { return current; } current = current.getParentMap(); } return null; }
private void copyProperties(DynamicObject fromObject) { ShapeImpl fromShape = (ShapeImpl) fromObject.getShape(); ShapeImpl toShape = getShape(); assert toShape.isRelated(fromShape); assert toShape.isValid(); assert !fromShape.isShared(); PropertyMap fromMap = fromShape.getPropertyMap(); for (Iterator<Property> toMapIt = toShape.getPropertyMap().reverseOrderedValueIterator(); toMapIt.hasNext();) { Property toProperty = toMapIt.next(); Property fromProperty = fromMap.get(toProperty.getKey()); // copy only if property has a location and it's not the same as the source location if (!toProperty.getLocation().isValue() && !toProperty.getLocation().equals(fromProperty.getLocation())) { toProperty.setInternal(this, fromProperty.get(fromObject, false)); assert toShape.isValid(); } } }
/** * Returns all (also hidden) Property objects in this shape. * * @param ascending desired order * @since 0.17 or earlier */ @TruffleBoundary @Override public final List<Property> getPropertyListInternal(boolean ascending) { Property[] props = new Property[this.propertyMap.size()]; int i = ascending ? props.length : 0; for (Iterator<Property> it = this.propertyMap.reverseOrderedValueIterator(); it.hasNext();) { Property current = it.next(); if (ascending) { props[--i] = current; } else { props[i++] = current; } } return Arrays.asList(props); }
/** @since 0.17 or earlier */ @TruffleBoundary public String toStringLimit(int limit) { StringBuilder sb = new StringBuilder(); sb.append('@'); sb.append(Integer.toHexString(hashCode())); if (!isValid()) { sb.append('!'); } sb.append("{"); for (Iterator<Property> iterator = propertyMap.reverseOrderedValueIterator(); iterator.hasNext();) { Property p = iterator.next(); sb.append(p); if (iterator.hasNext()) { sb.append(","); } if (sb.length() >= limit) { sb.append("..."); break; } sb.append("\n"); } sb.append("}"); return sb.toString(); }
@Override public int size() { return PropertyMap.this.size(); } };
/** @since 0.17 or earlier */ @Override public final Property getLastProperty() { return propertyMap.getLastProperty(); }
/** * Create a new shape that adds a property to the parent shape. */ private static ShapeImpl makeShapeWithAddedProperty(ShapeImpl parent, AddPropertyTransition addTransition) { Property addend = addTransition.getProperty(); BaseAllocator allocator = parent.allocator().addLocation(addend.getLocation()); PropertyMap newPropertyMap = parent.propertyMap.putCopy(addend); ShapeImpl newShape = parent.createShape(parent.layout, parent.sharedData, parent, parent.objectType, newPropertyMap, addTransition, allocator, parent.id); assert ((LocationImpl) addend.getLocation()).primitiveArrayCount() == 0 || newShape.hasPrimitiveArray; assert newShape.depth == allocator.depth; return newShape; }
/** * Get a property entry by string name. * * @param key the name to look up * @return a Property object, or null if not found * @since 0.17 or earlier */ @Override @TruffleBoundary public Property getProperty(Object key) { return propertyMap.get(key); }
/** @since 0.17 or earlier */ protected ShapeImpl(Layout layout, ObjectType operations, Object sharedData, int id) { this(layout, null, operations, sharedData, PropertyMap.empty(), null, layout.createAllocator(), id); }
/** @since 0.17 or earlier */ protected ShapeImpl directReplaceProperty(ShapeImpl shape, Property oldProperty, Property newProperty) { Transition replacePropertyTransition = new Transition.DirectReplacePropertyTransition(oldProperty, newProperty); ShapeImpl cachedShape = shape.queryTransition(replacePropertyTransition); if (cachedShape != null) { return ensureValid(cachedShape); } PropertyMap newPropertyMap = shape.getPropertyMap().replaceCopy(oldProperty, newProperty); BaseAllocator allocator = shape.allocator().addLocation(newProperty.getLocation()); ShapeImpl newShape = shape.createShape(shape.getLayout(), shape.getSharedData(), shape, shape.getObjectType(), newPropertyMap, replacePropertyTransition, allocator, shape.getId()); shape.addDirectTransition(replacePropertyTransition, newShape); return newShape; }
private void copyProperties(DynamicObject fromObject) { ShapeImpl fromShape = (ShapeImpl) fromObject.getShape(); ShapeImpl toShape = getShapeImpl(); assert toShape.isRelated(fromShape); assert toShape.isValid(); assert !fromShape.isShared(); PropertyMap fromMap = fromShape.getPropertyMap(); for (Iterator<Property> toMapIt = toShape.getPropertyMap().reverseOrderedValueIterator(); toMapIt.hasNext();) { Property toProperty = toMapIt.next(); Property fromProperty = fromMap.get(toProperty.getKey()); // copy only if property has a location and it's not the same as the source location if (!toProperty.getLocation().isValue() && !toProperty.getLocation().equals(fromProperty.getLocation())) { toProperty.setInternal(this, fromProperty.get(fromObject, false)); assert toShape.isValid(); } } }
/** * Returns all (also hidden) Property objects in this shape. * * @param ascending desired order * @since 0.17 or earlier */ @TruffleBoundary @Override public final List<Property> getPropertyListInternal(boolean ascending) { Property[] props = new Property[this.propertyMap.size()]; int i = ascending ? props.length : 0; for (Iterator<Property> it = this.propertyMap.reverseOrderedValueIterator(); it.hasNext();) { Property current = it.next(); if (ascending) { props[--i] = current; } else { props[i++] = current; } } return Arrays.asList(props); }
/** @since 0.17 or earlier */ @TruffleBoundary public String toStringLimit(int limit) { StringBuilder sb = new StringBuilder(); sb.append('@'); sb.append(Integer.toHexString(hashCode())); if (!isValid()) { sb.append('!'); } sb.append("{"); for (Iterator<Property> iterator = propertyMap.reverseOrderedValueIterator(); iterator.hasNext();) { Property p = iterator.next(); sb.append(p); if (iterator.hasNext()) { sb.append(","); } if (sb.length() >= limit) { sb.append("..."); break; } sb.append("\n"); } sb.append("}"); return sb.toString(); }
@Override public int size() { return PropertyMap.this.size(); } };
@Override public final Property getLastProperty() { return propertyMap.getLastProperty(); }
/** * Create a new shape that adds a property to the parent shape. * * @since 0.17 or earlier */ protected static ShapeImpl makeShapeWithAddedProperty(ShapeImpl parent, AddPropertyTransition addTransition) { Property addend = addTransition.getProperty(); BaseAllocator allocator = parent.allocator().addLocation(addend.getLocation()); PropertyMap newPropertyMap = parent.propertyMap.putCopy(addend); ShapeImpl newShape = parent.createShape(parent.layout, parent.sharedData, parent, parent.objectType, newPropertyMap, addTransition, allocator, parent.id); assert ((LocationImpl) addend.getLocation()).primitiveArrayCount() == 0 || newShape.hasPrimitiveArray; assert newShape.depth == allocator.depth; return newShape; }