Skip to content

Commit

Permalink
Use Set instead of Map for storing deleted properties ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Koval committed Mar 22, 2018
1 parent 9e854ca commit c4c363f
Showing 1 changed file with 10 additions and 8 deletions.
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.kernel.impl.api.state;

import java.util.Iterator;
import java.util.Set;
import java.util.function.Predicate;

import org.neo4j.helpers.collection.Iterators;
Expand All @@ -31,21 +32,22 @@
import org.neo4j.values.storable.Value;

import static java.util.Collections.emptyIterator;
import static java.util.Collections.newSetFromMap;

class PropertyContainerStateImpl implements PropertyContainerState
{
private final long id;

private VersionedHashMap<Integer, Value> addedProperties;
private VersionedHashMap<Integer, Value> changedProperties;
private VersionedHashMap<Integer, Object> removedProperties;
private Set<Integer> removedProperties;

private final Predicate<StorageProperty> excludePropertiesWeKnowAbout = new Predicate<StorageProperty>()
{
@Override
public boolean test( StorageProperty item )
{
return (removedProperties == null || !removedProperties.containsKey( item.propertyKeyId() ))
return (removedProperties == null || !removedProperties.contains( item.propertyKeyId() ))
&& (addedProperties == null || !addedProperties.containsKey( item.propertyKeyId() ))
&& (changedProperties == null || !changedProperties.containsKey( item.propertyKeyId() ));
}
Expand Down Expand Up @@ -99,7 +101,7 @@ void changeProperty( int propertyKeyId, Value value )

void addProperty( int propertyKeyId, Value value )
{
if ( removedProperties != null && removedProperties.remove( propertyKeyId ) != null )
if ( removedProperties != null && removedProperties.remove( propertyKeyId ) )
{
// This indicates the user did remove+add as two discrete steps, which should be translated to
// a single change operation.
Expand All @@ -121,9 +123,9 @@ void removeProperty( int propertyKeyId )
}
if ( removedProperties == null )
{
removedProperties = new VersionedHashMap<>();
removedProperties = newSetFromMap( new VersionedHashMap<>() );
}
removedProperties.put( propertyKeyId, Boolean.TRUE );
removedProperties.add( propertyKeyId );
if ( changedProperties != null )
{
changedProperties.remove( propertyKeyId );
Expand All @@ -145,7 +147,7 @@ public Iterator<StorageProperty> changedProperties()
@Override
public Iterator<Integer> removedProperties()
{
return removedProperties != null ? removedProperties.keySet().iterator() : emptyIterator();
return removedProperties != null ? removedProperties.iterator() : emptyIterator();
}

@Override
Expand Down Expand Up @@ -212,14 +214,14 @@ public StorageProperty getAddedProperty( int propertyKeyId )
@Override
public boolean isPropertyChangedOrRemoved( int propertyKey )
{
return (removedProperties != null && removedProperties.containsKey( propertyKey ))
return (removedProperties != null && removedProperties.contains( propertyKey ))
|| (changedProperties != null && changedProperties.containsKey( propertyKey ));
}

@Override
public boolean isPropertyRemoved( int propertyKeyId )
{
return removedProperties != null && removedProperties.containsKey( propertyKeyId );
return removedProperties != null && removedProperties.contains( propertyKeyId );
}

private Iterator<StorageProperty> toPropertyIterator( VersionedHashMap<Integer,Value> propertyMap )
Expand Down

0 comments on commit c4c363f

Please sign in to comment.