Example #1
0
        public JsSchema Add(int index, PropertyAttributes attributes, ref object[] values, object value)
        {
            // The entry shouldn't be in our schema yet.
            Debug.Assert(GetOffset(index) < 0);

            // Get or create the new schema.
            JsSchema schema = null;

            // Check whether we already have a transformation.
            if (_transformations != null)
                schema = _transformations.GetValue(MakeIndex(index, attributes));

            int newOffset;

            // Build the new schema if we don't have it yet and add it to the
            // list of transformations.
            if (schema == null)
            {
                schema = new JsSchema(this);

                // Apply the mutation to the new schema. We get a free entry or,
                // if there isn't any, increase the array size.

                var freeList = schema._freeList;
                if (freeList == null)
                {
                    schema.GrowFreeEntries();
                    freeList = schema._freeList;
                }

                schema._freeList = freeList.Next;
                newOffset = freeList.Index;

                schema._node = new Node(true, index, attributes, newOffset, _node);

                if (_transformations == null)
                    _transformations = new SchemaTransformationHashSet(InitialTransformationsSize);

                _transformations.Add(MakeIndex(index, attributes), schema);
            }
            else
            {
                newOffset = schema.GetOffset(index);

                // The attributes of this property of the new schema should
                // be the same as what we're adding.
                Debug.Assert(schema.GetAttributes(index) == attributes);
            }

            // Apply the transformation to the values array.
            if (_arraySize != schema._arraySize)
                Array.Resize(ref values, schema._arraySize);

            values[newOffset] = value;

            return schema;
        }
Example #2
0
 public SchemaTransformationHashSetDebugView(SchemaTransformationHashSet container)
 {
     _container = container;
 }
Example #3
0
        public JsSchema Remove(int index, ref object[] values)
        {
            int oldOffset = GetOffset(index);

            // The entry should be in our schema.
            Debug.Assert(oldOffset >= 0);

            // Get or create the new schema.
            JsSchema schema = null;

            // Check whether we already have a transformation.
            if (_transformations != null)
                schema = _transformations.GetValue(MakeIndex(index, 0));

            // Build the new schema if we don't have it yet and add it to the
            // list of transformations.
            if (schema == null)
            {
                schema = new JsSchema(this);

                // Apply the transformation to the schema and add the index to
                // the free list.

                schema._node = new Node(false, index, 0, -1, _node);

                schema._freeList = new FreeEntry(oldOffset, schema._freeList);

                // Add the transformation.

                if (_transformations == null)
                    _transformations = new SchemaTransformationHashSet();

                _transformations.Add(MakeIndex(index, 0), schema);
            }

            // Apply the transformation to the values array.
            values[oldOffset] = null;

            return schema;
        }
Example #4
0
        public SchemaTransformationHashSet(SchemaTransformationHashSet other)
        {
            if (other == null)
                throw new ArgumentNullException("other");

            _entries = new Entry[other._entries.Length];
            Array.Copy(other._entries, _entries, _entries.Length);
            Count = other.Count;
        }