提交 5a7618d5 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Reduce allocated garbage in Database.getAllSchemaObjects()

上级 a8748cb1
......@@ -51,7 +51,7 @@ public class DropSchema extends DefineCommand {
}
if (dropAction == ConstraintActionType.RESTRICT && !schema.isEmpty()) {
StatementBuilder buff = new StatementBuilder();
for (SchemaObject object : schema.getAll()) {
for (SchemaObject object : schema.getAll(null)) {
buff.appendExceptFirst(", ");
buff.append(object.getName());
}
......
......@@ -1564,7 +1564,7 @@ public class Database implements DataHandler {
initMetaTables();
ArrayList<SchemaObject> list = new ArrayList<>();
for (Schema schema : schemas.values()) {
list.addAll(schema.getAll());
schema.getAll(list);
}
return list;
}
......@@ -1581,7 +1581,7 @@ public class Database implements DataHandler {
}
ArrayList<SchemaObject> list = new ArrayList<>();
for (Schema schema : schemas.values()) {
list.addAll(schema.getAll(type));
schema.getAll(type, list);
}
return list;
}
......
......@@ -6,6 +6,7 @@
package org.h2.schema;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
......@@ -591,30 +592,46 @@ public class Schema extends DbObjectBase {
/**
* Get all objects.
*
* @return a (possible empty) list of all objects
* @param addTo
* list to add objects to, or {@code null} to allocate a new
* list
* @return the specified list with added objects, or a new (possibly empty) list
* with all objects
*/
public ArrayList<SchemaObject> getAll() {
ArrayList<SchemaObject> all = Utils.newSmallArrayList();
all.addAll(tablesAndViews.values());
all.addAll(synonyms.values());
all.addAll(sequences.values());
all.addAll(indexes.values());
all.addAll(triggers.values());
all.addAll(constraints.values());
all.addAll(constants.values());
all.addAll(functions.values());
return all;
public ArrayList<SchemaObject> getAll(ArrayList<SchemaObject> addTo) {
if (addTo == null) {
addTo = Utils.newSmallArrayList();
}
addTo.addAll(tablesAndViews.values());
addTo.addAll(synonyms.values());
addTo.addAll(sequences.values());
addTo.addAll(indexes.values());
addTo.addAll(triggers.values());
addTo.addAll(constraints.values());
addTo.addAll(constants.values());
addTo.addAll(functions.values());
return addTo;
}
/**
* Get all objects of the given type.
*
* @param type the object type
* @return a (possible empty) list of all objects
*/
public ArrayList<SchemaObject> getAll(int type) {
Map<String, SchemaObject> map = getMap(type);
return new ArrayList<>(map.values());
* @param type
* the object type
* @param addTo
* list to add objects to, or {@code null} to allocate a new
* list
* @return the specified list with added objects, or a new (possibly empty) list
* with objects of the given type
*/
public ArrayList<SchemaObject> getAll(int type, ArrayList<SchemaObject> addTo) {
Collection<SchemaObject> values = getMap(type).values();
if (addTo != null) {
addTo.addAll(values);
} else {
addTo = new ArrayList<>(values);
}
return addTo;
}
/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论