Skip to content

Commit

Permalink
Optimize lazy data holder generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
joehni committed Dec 28, 2021
1 parent d6d8a27 commit 3b6f80c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Copyright (C) 2004, 2005, 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2009, 2011, 2014, 2015, 2018
* XStream Committers.
* Copyright (C) 2006, 2007, 2009, 2011, 2014, 2015, 2018, 2021 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand All @@ -12,6 +11,7 @@
*/
package com.thoughtworks.xstream.core;

import java.util.Collections;
import java.util.Iterator;

import com.thoughtworks.xstream.converters.ConversionException;
Expand Down Expand Up @@ -85,8 +85,7 @@ public void start(final Object item, final DataHolder dataHolder) {

@Override
public Object get(final Object key) {
lazilyCreateDataHolder();
return dataHolder.get(key);
return dataHolder != null ? dataHolder.get(key) : null;
}

@Override
Expand All @@ -97,8 +96,7 @@ public void put(final Object key, final Object value) {

@Override
public Iterator<Object> keys() {
lazilyCreateDataHolder();
return dataHolder.keys();
return dataHolder != null ? dataHolder.keys() : Collections.EMPTY_MAP.keySet().iterator();
}

private void lazilyCreateDataHolder() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004, 2005, 2006 Joe Walnes.
* Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014, 2015, 2018 XStream Committers.
* Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014, 2015, 2018, 2021 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand All @@ -11,6 +11,7 @@
*/
package com.thoughtworks.xstream.core;

import java.util.Collections;
import java.util.Iterator;

import com.thoughtworks.xstream.converters.ConversionException;
Expand Down Expand Up @@ -114,8 +115,7 @@ public Class<?> getRequiredType() {

@Override
public Object get(final Object key) {
lazilyCreateDataHolder();
return dataHolder.get(key);
return dataHolder != null ? dataHolder.get(key) : null;
}

@Override
Expand All @@ -126,8 +126,7 @@ public void put(final Object key, final Object value) {

@Override
public Iterator<Object> keys() {
lazilyCreateDataHolder();
return dataHolder.keys();
return dataHolder != null ? dataHolder.keys() : Collections.EMPTY_MAP.keySet().iterator();
}

private void lazilyCreateDataHolder() {
Expand Down

0 comments on commit 3b6f80c

Please sign in to comment.