|
From: <tho...@us...> - 2010-09-29 19:55:36
|
Revision: 3685
http://bigdata.svn.sourceforge.net/bigdata/?rev=3685&view=rev
Author: thompsonbry
Date: 2010-09-29 19:55:30 +0000 (Wed, 29 Sep 2010)
Log Message:
-----------
Added NOARGS and NOANNS for BOPs that we create a lot of. These are a singleton empty array and empty map respectively.
Modified Paths:
--------------
branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpBase.java
branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/Constant.java
branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/Var.java
Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpBase.java
===================================================================
--- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpBase.java 2010-09-29 19:54:27 UTC (rev 3684)
+++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpBase.java 2010-09-29 19:55:30 UTC (rev 3685)
@@ -71,6 +71,20 @@
private static final long serialVersionUID = 1L;
/**
+ * An empty array.
+ */
+ static protected final transient BOp[] NOARGS = new BOp[] {};
+
+ /**
+ * An empty immutable annotations map.
+ *
+ * @todo This is for things like {@link Constant} and {@link Var} which are
+ * never annotated. However, i'm not sure if this is a good idea or
+ * not. A "copy on write" map might be better.
+ */
+ static protected final transient Map<String,Object> NOANNS = Collections.emptyMap();
+
+ /**
* The argument values - <strong>direct access to this field is
* discouraged</strong> - the field is protected to support
* <em>mutation</em> APIs and should not be relied on for other purposes.
@@ -288,6 +302,10 @@
/** deep copy the arguments. */
static protected BOp[] deepCopy(final BOp[] a) {
+ if (a == NOARGS) {
+ // fast path for zero arity operators.
+ return a;
+ }
final BOp[] t = new BOp[a.length];
for (int i = 0; i < a.length; i++) {
t[i] = a[i] == null ? null : a[i].clone();
@@ -311,7 +329,11 @@
* containing an ontology or some conditional assertions with a query
* plan.
*/
- static protected Map<String,Object> deepCopy(final Map<String,Object> a) {
+ static protected Map<String, Object> deepCopy(final Map<String, Object> a) {
+ if (a == NOANNS) {
+ // Fast past for immutable, empty annotations.
+ return a;
+ }
// allocate map.
final Map<String, Object> t = new LinkedHashMap<String, Object>(a
.size());
Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/Constant.java
===================================================================
--- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/Constant.java 2010-09-29 19:54:27 UTC (rev 3684)
+++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/Constant.java 2010-09-29 19:55:30 UTC (rev 3685)
@@ -66,13 +66,16 @@
* @param op
*/
public Constant(final Constant<E> op) {
+
super(op);
+
this.value = op.value;
+
}
public Constant(final E value) {
- super(new BOp[] {}, null/* annotations */);
+ super(NOARGS, NOANNS);
if (value == null)
throw new IllegalArgumentException();
Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/Var.java
===================================================================
--- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/Var.java 2010-09-29 19:54:27 UTC (rev 3684)
+++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/Var.java 2010-09-29 19:55:30 UTC (rev 3685)
@@ -58,7 +58,8 @@
*/
private Var(final String name) {
- super(new BOp[] {}, null/* annotations */);
+// super(new BOp[] {}, null/* annotations */);
+ super(NOARGS, NOANNS);
assert name != null;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|