[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/2] Avoid creating new Arrays and Lists on every struct instantiation



Signed-off-by: Claudio Bley <cbley av-test de>
---
 src/main/java/org/libvirt/jna/virConnectAuth.java  |   12 +++++++++---
 .../java/org/libvirt/jna/virConnectCredential.java |   12 +++++++++---
 .../java/org/libvirt/jna/virDomainBlockInfo.java   |   12 +++++++++---
 .../java/org/libvirt/jna/virDomainBlockStats.java  |   12 +++++++++---
 src/main/java/org/libvirt/jna/virDomainInfo.java   |   12 +++++++++---
 .../org/libvirt/jna/virDomainInterfaceStats.java   |   12 +++++++++---
 .../java/org/libvirt/jna/virDomainJobInfo.java     |   12 +++++++++---
 .../java/org/libvirt/jna/virDomainMemoryStats.java |   10 ++++++++--
 src/main/java/org/libvirt/jna/virError.java        |   12 +++++++++---
 src/main/java/org/libvirt/jna/virNodeInfo.java     |   12 +++++++++---
 .../java/org/libvirt/jna/virSchedParameter.java    |   12 +++++++++---
 .../java/org/libvirt/jna/virStoragePoolInfo.java   |   12 +++++++++---
 .../java/org/libvirt/jna/virStorageVolInfo.java    |   12 +++++++++---
 src/main/java/org/libvirt/jna/virVcpuInfo.java     |   12 +++++++++---
 14 files changed, 125 insertions(+), 41 deletions(-)

diff --git a/src/main/java/org/libvirt/jna/virConnectAuth.java b/src/main/java/org/libvirt/jna/virConnectAuth.java
index 369d2e5..ece61f6 100644
--- a/src/main/java/org/libvirt/jna/virConnectAuth.java
+++ b/src/main/java/org/libvirt/jna/virConnectAuth.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Pointer;
 import com.sun.jna.Structure;
 
@@ -12,8 +15,11 @@ public class virConnectAuth extends Structure {
     public Libvirt.VirConnectAuthCallback cb;
     public Pointer cbdata;
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
-            "credtype", "ncredtype", "cb", "cbdata" });
+    private static final List fields = Arrays.asList(
+            "credtype", "ncredtype", "cb", "cbdata");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virConnectCredential.java b/src/main/java/org/libvirt/jna/virConnectCredential.java
index dbfc38e..6dd4a75 100644
--- a/src/main/java/org/libvirt/jna/virConnectCredential.java
+++ b/src/main/java/org/libvirt/jna/virConnectCredential.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Structure;
 
 /**
@@ -14,9 +17,12 @@ public class virConnectCredential extends Structure implements Structure.ByRefer
     public String result;
     public int resultlen;
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
+    private static final List fields = Arrays.asList(
             "type", "prompt", "challenge", "defresult",
-            "result", "resultlen" });
+            "result", "resultlen");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virDomainBlockInfo.java b/src/main/java/org/libvirt/jna/virDomainBlockInfo.java
index cbd7385..fb1b845 100644
--- a/src/main/java/org/libvirt/jna/virDomainBlockInfo.java
+++ b/src/main/java/org/libvirt/jna/virDomainBlockInfo.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Structure;
 
 public class virDomainBlockInfo extends Structure {
@@ -7,8 +10,11 @@ public class virDomainBlockInfo extends Structure {
     public long allocation;
     public long physical;
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
-            "capacity", "allocation", "physical" });
+    private static final List fields = Arrays.asList(
+            "capacity", "allocation", "physical");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virDomainBlockStats.java b/src/main/java/org/libvirt/jna/virDomainBlockStats.java
index 71041cc..a7331f6 100644
--- a/src/main/java/org/libvirt/jna/virDomainBlockStats.java
+++ b/src/main/java/org/libvirt/jna/virDomainBlockStats.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Structure;
 
 /**
@@ -17,8 +20,11 @@ public class virDomainBlockStats extends Structure {
     public long errs; // this is a long long in the code, so a long mapping is
     // correct
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
-            "rd_req", "rd_bytes", "wr_req", "wr_bytes", "errs" });
+    private static final List fields = Arrays.asList(
+            "rd_req", "rd_bytes", "wr_req", "wr_bytes", "errs");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virDomainInfo.java b/src/main/java/org/libvirt/jna/virDomainInfo.java
index 994042a..0b667f6 100644
--- a/src/main/java/org/libvirt/jna/virDomainInfo.java
+++ b/src/main/java/org/libvirt/jna/virDomainInfo.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.NativeLong;
 import com.sun.jna.Structure;
 
@@ -13,8 +16,11 @@ public class virDomainInfo extends Structure {
     public short nrVirtCpu;
     public long cpuTime;
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
-            "state", "maxMem", "memory", "nrVirtCpu", "cpuTime" });
+    private static final List fields = Arrays.asList(
+            "state", "maxMem", "memory", "nrVirtCpu", "cpuTime");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java b/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java
index dcdd529..eea6a49 100644
--- a/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java
+++ b/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Structure;
 
 /**
@@ -23,9 +26,12 @@ public class virDomainInterfaceStats extends Structure {
     public long tx_drop; // this is a long long in the code, so a long mapping
     // is correct
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
+    private static final List fields = Arrays.asList(
             "rx_bytes", "rx_packets", "rx_errs", "rx_drop",
-            "tx_bytes", "tx_packets", "tx_errs", "tx_drop" });
+            "tx_bytes", "tx_packets", "tx_errs", "tx_drop");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virDomainJobInfo.java b/src/main/java/org/libvirt/jna/virDomainJobInfo.java
index af934ad..0398901 100644
--- a/src/main/java/org/libvirt/jna/virDomainJobInfo.java
+++ b/src/main/java/org/libvirt/jna/virDomainJobInfo.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Structure;
 
 public class virDomainJobInfo extends Structure {
@@ -16,10 +19,13 @@ public class virDomainJobInfo extends Structure {
     public long fileProcessed;
     public long fileRemaining;
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
+    private static final List fields = Arrays.asList(
             "type", "timeElapsed", "timeRemaining", "dataTotal",
             "dataProcessed", "dataRemaining", "memTotal", "memProcessed",
-            "memRemaining", "fileTotal", "fileProcessed", "fileRemaining" });
+            "memRemaining", "fileTotal", "fileProcessed", "fileRemaining");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virDomainMemoryStats.java b/src/main/java/org/libvirt/jna/virDomainMemoryStats.java
index ec7b29e..b14fb95 100644
--- a/src/main/java/org/libvirt/jna/virDomainMemoryStats.java
+++ b/src/main/java/org/libvirt/jna/virDomainMemoryStats.java
@@ -1,12 +1,18 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Structure;
 
 public class virDomainMemoryStats extends Structure {
     public int tag ;
     public long val ;
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] { "tag", "val" });
+    private static final List fields = Arrays.asList( "tag", "val");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virError.java b/src/main/java/org/libvirt/jna/virError.java
index 9009280..3c11311 100644
--- a/src/main/java/org/libvirt/jna/virError.java
+++ b/src/main/java/org/libvirt/jna/virError.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Pointer;
 import com.sun.jna.Structure;
 
@@ -20,9 +23,12 @@ public class virError extends Structure {
     public int int2;
     public NetworkPointer net;
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
+    private static final List fields = Arrays.asList(
             "code", "domain", "message", "level", "conn", "dom",
-            "str1", "str2", "str3", "int1", "int2", "net" });
+            "str1", "str2", "str3", "int1", "int2", "net");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virNodeInfo.java b/src/main/java/org/libvirt/jna/virNodeInfo.java
index f13eddc..9ff1251 100644
--- a/src/main/java/org/libvirt/jna/virNodeInfo.java
+++ b/src/main/java/org/libvirt/jna/virNodeInfo.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.NativeLong;
 import com.sun.jna.Structure;
 
@@ -22,9 +25,12 @@ public class virNodeInfo extends Structure {
     public int cores;
     public int threads;
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
+    private static final List fields = Arrays.asList(
             "model", "memory", "cpus", "mhz", "nodes",
-            "sockets", "cores", "threads" });
+            "sockets", "cores", "threads");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virSchedParameter.java b/src/main/java/org/libvirt/jna/virSchedParameter.java
index 9496121..f579ef0 100644
--- a/src/main/java/org/libvirt/jna/virSchedParameter.java
+++ b/src/main/java/org/libvirt/jna/virSchedParameter.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Structure;
 
 /**
@@ -10,8 +13,11 @@ public class virSchedParameter extends Structure {
     public int type;
     public virSchedParameterValue value;
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
-            "field", "type", "value" });
+    private static final List fields = Arrays.asList(
+            "field", "type", "value");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virStoragePoolInfo.java b/src/main/java/org/libvirt/jna/virStoragePoolInfo.java
index 7f370cd..fe20f0f 100644
--- a/src/main/java/org/libvirt/jna/virStoragePoolInfo.java
+++ b/src/main/java/org/libvirt/jna/virStoragePoolInfo.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Structure;
 
 /**
@@ -14,8 +17,11 @@ public class virStoragePoolInfo extends Structure {
     public long available; // this is a long long in the code, so a long mapping
     // is correct
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
-            "state", "capacity", "allocation", "available" });
+    private static final List fields = Arrays.asList(
+            "state", "capacity", "allocation", "available");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virStorageVolInfo.java b/src/main/java/org/libvirt/jna/virStorageVolInfo.java
index a02219e..93132ea 100644
--- a/src/main/java/org/libvirt/jna/virStorageVolInfo.java
+++ b/src/main/java/org/libvirt/jna/virStorageVolInfo.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Structure;
 
 /**
@@ -12,8 +15,11 @@ public class virStorageVolInfo extends Structure {
     public long allocation; // this is a long long in the code, so a long
     // mapping is correct
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
-            "type", "capacity", "allocation" });
+    private static final List fields = Arrays.asList(
+            "type", "capacity", "allocation");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
diff --git a/src/main/java/org/libvirt/jna/virVcpuInfo.java b/src/main/java/org/libvirt/jna/virVcpuInfo.java
index e5f4363..96eca2f 100644
--- a/src/main/java/org/libvirt/jna/virVcpuInfo.java
+++ b/src/main/java/org/libvirt/jna/virVcpuInfo.java
@@ -1,5 +1,8 @@
 package org.libvirt.jna;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.sun.jna.Structure;
 
 /**
@@ -12,8 +15,11 @@ public class virVcpuInfo extends Structure {
     // is correct
     public int cpu;
 
-    protected java.util.List getFieldOrder() {
-        return java.util.Arrays.asList(new String[] {
-            "number", "state", "cpuTime", "cpu" });
+    private static final List fields = Arrays.asList(
+            "number", "state", "cpuTime", "cpu");
+
+    @Override
+    protected List getFieldOrder() {
+        return fields;
     }
 }
-- 
1.7.9.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]