Optimization: grow ourselves to the needed capacity prior to
fully reading elements off the stream to avoid repeatedly allocating storage arrays and copying or rehashing the elements. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3818 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: StreamableArrayList.java,v 1.2 2004/08/27 02:20:36 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -57,6 +57,7 @@ public class StreamableArrayList extends ArrayList
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
int ecount = in.readInt();
|
||||
ensureCapacity(ecount);
|
||||
for (int ii = 0; ii < ecount; ii++) {
|
||||
add(in.readObject());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: StreamableHashIntMap.java,v 1.4 2004/08/27 02:20:36 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -79,6 +79,7 @@ public class StreamableHashIntMap extends HashIntMap
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
int ecount = in.readInt();
|
||||
ensureCapacity(ecount);
|
||||
for (int ii = 0; ii < ecount; ii++) {
|
||||
int key = in.readInt();
|
||||
put(key, in.readObject());
|
||||
|
||||
@@ -79,6 +79,7 @@ public class StreamableIntIntMap extends IntIntMap
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
int ecount = in.readInt();
|
||||
ensureCapacity(ecount);
|
||||
for (int ii = 0; ii < ecount; ii++) {
|
||||
int key = in.readInt();
|
||||
put(key, in.readInt());
|
||||
|
||||
Reference in New Issue
Block a user