From 055aac9b5589d60ea57d3015ba2b8c0217124696 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 16 Sep 2009 21:13:07 +0000 Subject: [PATCH] Use Joiner instead of StringBuilder, in some places. Use String concatination in others (it's faster in actionscript than in Java) git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5959 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/io/SimpleStreamableObject.as | 15 +++--- .../presents/dobj/AttributeChangedEvent.as | 9 ++-- .../threerings/presents/dobj/CompoundEvent.as | 13 ++--- src/as/com/threerings/presents/dobj/DEvent.as | 18 +++---- .../com/threerings/presents/dobj/DObject.as | 23 ++++---- src/as/com/threerings/presents/dobj/DSet.as | 6 +-- .../presents/dobj/ElementUpdatedEvent.as | 10 ++-- .../presents/dobj/EntryAddedEvent.as | 9 ++-- .../presents/dobj/EntryRemovedEvent.as | 9 ++-- .../presents/dobj/EntryUpdatedEvent.as | 12 ++--- .../dobj/InvocationNotificationEvent.as | 11 ++-- .../presents/dobj/InvocationRequestEvent.as | 11 ++-- .../presents/dobj/InvocationResponseEvent.as | 11 ++-- .../threerings/presents/dobj/MessageEvent.as | 9 ++-- .../threerings/presents/dobj/NamedEvent.as | 8 +-- .../presents/dobj/ObjectAddedEvent.as | 9 ++-- .../presents/dobj/ObjectDestroyedEvent.as | 9 ---- .../presents/dobj/ObjectRemovedEvent.as | 9 ++-- .../com/threerings/presents/dobj/OidList.as | 8 +-- .../threerings/presents/net/Credentials.as | 54 ++----------------- .../threerings/presents/net/ServiceCreds.as | 7 ++- .../presents/net/UsernamePasswordCreds.as | 24 ++------- src/as/com/threerings/util/MessageBundle.as | 22 ++++---- 23 files changed, 102 insertions(+), 214 deletions(-) diff --git a/src/as/com/threerings/io/SimpleStreamableObject.as b/src/as/com/threerings/io/SimpleStreamableObject.as index 999e51fbb..db8ef6c69 100644 --- a/src/as/com/threerings/io/SimpleStreamableObject.as +++ b/src/as/com/threerings/io/SimpleStreamableObject.as @@ -21,9 +21,7 @@ package com.threerings.io { -import com.threerings.util.ClassUtil; -import com.threerings.util.StringBuilder; -import com.threerings.util.StringUtil; +import com.threerings.util.Joiner; /** * A simple serializable object implements the {@link Streamable} @@ -49,19 +47,18 @@ public class SimpleStreamableObject implements Streamable */ public function toString () :String { - var buf :StringBuilder = new StringBuilder("["); - buf.append(ClassUtil.tinyClassName(this)).append("("); - toStringBuilder(buf); - return buf.append(")]").toString(); + var j :Joiner = Joiner.createFor(this); + toStringJoiner(j); + return j.toString(); } /** * Handles the toString-ification of all public members. Derived * classes can override and include non-public members if desired. */ - protected function toStringBuilder (buf :StringBuilder): void + protected function toStringJoiner (j :Joiner): void { - StringUtil.fieldsToString(buf, this); + j.addFields(this); } } } diff --git a/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as b/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as index 4e940ea7c..f3b9aaf17 100644 --- a/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as +++ b/src/as/com/threerings/presents/dobj/AttributeChangedEvent.as @@ -25,7 +25,7 @@ import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; import com.threerings.util.Boxed; -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; /** * An attribute changed event is dispatched when a single attribute of a @@ -107,11 +107,10 @@ public class AttributeChangedEvent extends NamedEvent } // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("CHANGE:"); - super.toStringBuf(buf); - buf.append(", value=", _value); + super.toStringJoiner(j); + j.add("value", _value); } override public function writeObject (out :ObjectOutputStream) :void diff --git a/src/as/com/threerings/presents/dobj/CompoundEvent.as b/src/as/com/threerings/presents/dobj/CompoundEvent.as index 18e836796..f5cbfe06f 100644 --- a/src/as/com/threerings/presents/dobj/CompoundEvent.as +++ b/src/as/com/threerings/presents/dobj/CompoundEvent.as @@ -24,8 +24,8 @@ package com.threerings.presents.dobj { import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; +import com.threerings.util.Joiner; import com.threerings.util.StreamableArrayList; -import com.threerings.util.StringBuilder; /** * Used to manage and submit groups of events on a collection of distributed objects in a single @@ -90,15 +90,10 @@ public class CompoundEvent extends DEvent } // from DObject - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("COMPOUND:"); - super.toStringBuf(buf); - - var nn :int = _events.size(); - for (var ii :int = 0; ii < nn; ii++) { - buf.append(", ", _events.get(ii)); - } + super.toStringJoiner(j); + j.addArgsArray(_events.asArray()); } // from DObject diff --git a/src/as/com/threerings/presents/dobj/DEvent.as b/src/as/com/threerings/presents/dobj/DEvent.as index c14907285..afb9e195a 100644 --- a/src/as/com/threerings/presents/dobj/DEvent.as +++ b/src/as/com/threerings/presents/dobj/DEvent.as @@ -25,7 +25,7 @@ import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; import com.threerings.io.Streamable; -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; public /* abstract */ class DEvent implements Streamable @@ -96,21 +96,19 @@ public /* abstract */ class DEvent */ public function toString () :String { - var buf :StringBuilder = new StringBuilder(); - buf.append("["); - toStringBuf(buf); - buf.append("]"); - return buf.toString(); + var j :Joiner = Joiner.createFor(this); + toStringJoiner(j); + return j.toString(); } /** * This should be overridden by derived classes (which should be sure - * to call super.toString()) to append the derived class - * specific event information to the string buffer. + * to call super.toStringJoiner() first) to append the derived class + * specific event information onto the String representation. */ - protected function toStringBuf (buf :StringBuilder) :void + protected function toStringJoiner (j :Joiner) :void { - buf.append("targetOid=", _toid); + j.add("targetOid", _toid); } /** The oid of the object that is the target of this event. */ diff --git a/src/as/com/threerings/presents/dobj/DObject.as b/src/as/com/threerings/presents/dobj/DObject.as index 981349b0e..f1d31fa86 100644 --- a/src/as/com/threerings/presents/dobj/DObject.as +++ b/src/as/com/threerings/presents/dobj/DObject.as @@ -26,8 +26,8 @@ import flash.errors.IllegalOperationError; import flash.events.EventDispatcher; import com.threerings.util.ClassUtil; +import com.threerings.util.Joiner; import com.threerings.util.Log; -import com.threerings.util.StringBuilder; import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; @@ -157,34 +157,33 @@ public class DObject // extends EventDispatcher */ public function which () :String { - var buf :StringBuilder = new StringBuilder(); - whichBuf(buf); - return buf.toString(); + var j :Joiner = Joiner.createFor(this); + whichJoiner(j); + return j.toString(); } /** * Used to briefly describe this distributed object. */ - protected function whichBuf (buf :StringBuilder) :void + protected function whichJoiner (j :Joiner) :void { - buf.append(ClassUtil.shortClassName(this), ":", _oid); + j.addArgs(_oid); } // documentation inherited public function toString () :String { - var buf :StringBuilder = new StringBuilder("["); - toStringBuf(buf); - buf.append("]"); - return buf.toString(); + var j :Joiner = Joiner.createFor(this); + toStringJoiner(j); + return j.toString(); } /** * Generates a string representation of this object. */ - public function toStringBuf (buf :StringBuilder) :void + public function toStringJoiner (j :Joiner) :void { - buf.append("oid=", _oid); + j.add("oid", _oid); } /** diff --git a/src/as/com/threerings/presents/dobj/DSet.as b/src/as/com/threerings/presents/dobj/DSet.as index 2d8e59468..de6dc48ed 100644 --- a/src/as/com/threerings/presents/dobj/DSet.as +++ b/src/as/com/threerings/presents/dobj/DSet.as @@ -26,7 +26,6 @@ import com.threerings.util.Cloneable; import com.threerings.util.Equalable; import com.threerings.util.Iterator; import com.threerings.util.Log; -import com.threerings.util.StringBuilder; import com.threerings.util.Util; import com.threerings.io.ObjectInputStream; @@ -225,10 +224,7 @@ public class DSet */ public function toString () :String { - var buf :StringBuilder = new StringBuilder("("); - buf.append(_entries.toString()); - buf.append(")"); - return buf.toString(); + return "(" + _entries.toString() + ")"; } // documentation inherited from interface Streamable diff --git a/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as b/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as index 48d006396..f186a36e1 100644 --- a/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as +++ b/src/as/com/threerings/presents/dobj/ElementUpdatedEvent.as @@ -25,7 +25,7 @@ import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; import com.threerings.util.Boxed; -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; /** * An element updated event is dispatched when an element of an array @@ -132,12 +132,10 @@ public class ElementUpdatedEvent extends NamedEvent } // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("UPDATE:"); - super.toStringBuf(buf); - buf.append(", value=", _value); - buf.append(", index=", _index); + super.toStringJoiner(j); + j.add("value", _value, "index", _index); } protected var _value :Object; diff --git a/src/as/com/threerings/presents/dobj/EntryAddedEvent.as b/src/as/com/threerings/presents/dobj/EntryAddedEvent.as index c4d7423ce..9931d2b5e 100644 --- a/src/as/com/threerings/presents/dobj/EntryAddedEvent.as +++ b/src/as/com/threerings/presents/dobj/EntryAddedEvent.as @@ -24,8 +24,8 @@ package com.threerings.presents.dobj { import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; +import com.threerings.util.Joiner; import com.threerings.util.Log; -import com.threerings.util.StringBuilder; /** * An entry added event is dispatched when an entry is added to a {@link @@ -88,11 +88,10 @@ public class EntryAddedEvent extends NamedEvent } // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("ELADD:"); - super.toStringBuf(buf); - buf.append(", entry=", _entry); + super.toStringJoiner(j); + j.add("entry", _entry); } override public function writeObject (out :ObjectOutputStream) :void diff --git a/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as b/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as index dcb08cd83..067fdaa1b 100644 --- a/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as +++ b/src/as/com/threerings/presents/dobj/EntryRemovedEvent.as @@ -25,8 +25,8 @@ import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; import com.threerings.util.Boxed; +import com.threerings.util.Joiner; import com.threerings.util.Log; -import com.threerings.util.StringBuilder; /** * An entry removed event is dispatched when an entry is removed from a @@ -107,11 +107,10 @@ public class EntryRemovedEvent extends NamedEvent } // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("ELREM:"); - super.toStringBuf(buf); - buf.append(", key=", _key); + super.toStringJoiner(j); + j.add("key", _key); } override public function writeObject (out :ObjectOutputStream) :void diff --git a/src/as/com/threerings/presents/dobj/EntryUpdatedEvent.as b/src/as/com/threerings/presents/dobj/EntryUpdatedEvent.as index e51e45614..90bb15bd8 100644 --- a/src/as/com/threerings/presents/dobj/EntryUpdatedEvent.as +++ b/src/as/com/threerings/presents/dobj/EntryUpdatedEvent.as @@ -24,8 +24,8 @@ package com.threerings.presents.dobj { import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; +import com.threerings.util.Joiner; import com.threerings.util.Log; -import com.threerings.util.StringBuilder; /** * An entry updated event is dispatched when an entry of a {@link DSet} is @@ -89,8 +89,7 @@ public class EntryUpdatedEvent extends NamedEvent _oldEntry = dset.update(_entry); if (_oldEntry == null) { // complain if we didn't update anything - Log.getLog(this).warning("No matching entry to update " + - "[entry=" + this + ", set=" + dset + "]."); + Log.getLog(this).warning("No matching entry to update", "entry", this, "set", dset); return false; } } @@ -106,11 +105,10 @@ public class EntryUpdatedEvent extends NamedEvent } // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("ELUPD:"); - super.toStringBuf(buf); - buf.append(", entry=", _entry); + super.toStringJoiner(j); + j.add("entry", _entry); } override public function writeObject (out :ObjectOutputStream) :void diff --git a/src/as/com/threerings/presents/dobj/InvocationNotificationEvent.as b/src/as/com/threerings/presents/dobj/InvocationNotificationEvent.as index 7e4e489c7..b5325aade 100644 --- a/src/as/com/threerings/presents/dobj/InvocationNotificationEvent.as +++ b/src/as/com/threerings/presents/dobj/InvocationNotificationEvent.as @@ -25,7 +25,7 @@ import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; import com.threerings.io.TypedArray; -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; /** * Used to dispatch an invocation notification from the server to a @@ -103,13 +103,10 @@ public class InvocationNotificationEvent extends DEvent } // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("INOT:"); - super.toStringBuf(buf); - buf.append(", rcvId=", _receiverId); - buf.append(", methodId=", _methodId); - buf.append(", args=", _args); + super.toStringJoiner(j); + j.add("rcvId", _receiverId, "methodId", _methodId, "args", _args); } // documentation inherited diff --git a/src/as/com/threerings/presents/dobj/InvocationRequestEvent.as b/src/as/com/threerings/presents/dobj/InvocationRequestEvent.as index 8cc8904d2..557c1215a 100644 --- a/src/as/com/threerings/presents/dobj/InvocationRequestEvent.as +++ b/src/as/com/threerings/presents/dobj/InvocationRequestEvent.as @@ -24,7 +24,7 @@ package com.threerings.presents.dobj { import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; /** * Used to dispatch an invocation request from the client to the server. @@ -99,13 +99,10 @@ public class InvocationRequestEvent extends DEvent } // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("IREQ:"); - super.toStringBuf(buf); - buf.append(", code=", _invCode); - buf.append(", methodId=", _methodId); - buf.append(", args=", _args); + super.toStringJoiner(j); + j.add("code", _invCode, "methodId", _methodId, "args", _args); } // documentation inherited from interface Streamable diff --git a/src/as/com/threerings/presents/dobj/InvocationResponseEvent.as b/src/as/com/threerings/presents/dobj/InvocationResponseEvent.as index d52d2c12e..fd0ebb1c7 100644 --- a/src/as/com/threerings/presents/dobj/InvocationResponseEvent.as +++ b/src/as/com/threerings/presents/dobj/InvocationResponseEvent.as @@ -24,7 +24,7 @@ package com.threerings.presents.dobj { import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; /** * Used to dispatch an invocation response from the server to the client. @@ -99,13 +99,10 @@ public class InvocationResponseEvent extends DEvent } // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("IRSP:"); - super.toStringBuf(buf); - buf.append(", reqid=", _requestId); - buf.append(", methodId=", _methodId); - buf.append(", args=", _args); + super.toStringJoiner(j); + j.add("reqId", _requestId, "methodId", _methodId, "args", _args); } // documentation inherited diff --git a/src/as/com/threerings/presents/dobj/MessageEvent.as b/src/as/com/threerings/presents/dobj/MessageEvent.as index 4ed93f7c0..1563c89c9 100644 --- a/src/as/com/threerings/presents/dobj/MessageEvent.as +++ b/src/as/com/threerings/presents/dobj/MessageEvent.as @@ -26,7 +26,7 @@ import com.threerings.io.ObjectOutputStream; import com.threerings.io.TypedArray; import com.threerings.util.Boxed; -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; /** * A message event is used to dispatch a message to all subscribers of a @@ -97,11 +97,10 @@ public class MessageEvent extends NamedEvent } // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("MSG:"); - super.toStringBuf(buf); - buf.append(", args=", _args); + super.toStringJoiner(j); + j.add("args", _args); } // documentation inherited diff --git a/src/as/com/threerings/presents/dobj/NamedEvent.as b/src/as/com/threerings/presents/dobj/NamedEvent.as index fa319eb81..5c19048a0 100644 --- a/src/as/com/threerings/presents/dobj/NamedEvent.as +++ b/src/as/com/threerings/presents/dobj/NamedEvent.as @@ -21,7 +21,7 @@ package com.threerings.presents.dobj { -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; @@ -53,10 +53,10 @@ public /* abstract */ class NamedEvent extends DEvent return _name; } - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - super.toStringBuf(buf); - buf.append(", name=", _name); + super.toStringJoiner(j); + j.add("name", _name); } override public function writeObject (out :ObjectOutputStream) :void diff --git a/src/as/com/threerings/presents/dobj/ObjectAddedEvent.as b/src/as/com/threerings/presents/dobj/ObjectAddedEvent.as index b9971d502..7d072a845 100644 --- a/src/as/com/threerings/presents/dobj/ObjectAddedEvent.as +++ b/src/as/com/threerings/presents/dobj/ObjectAddedEvent.as @@ -24,7 +24,7 @@ package com.threerings.presents.dobj { import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; /** * An object added event is dispatched when an object is added to an @@ -97,11 +97,10 @@ public class ObjectAddedEvent extends NamedEvent } // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("OBJADD:"); - super.toStringBuf(buf); - buf.append(", oid=", _oid); + super.toStringJoiner(j); + j.add("oid", _oid); } protected var _oid :int; diff --git a/src/as/com/threerings/presents/dobj/ObjectDestroyedEvent.as b/src/as/com/threerings/presents/dobj/ObjectDestroyedEvent.as index 714916866..5cb9d14f5 100644 --- a/src/as/com/threerings/presents/dobj/ObjectDestroyedEvent.as +++ b/src/as/com/threerings/presents/dobj/ObjectDestroyedEvent.as @@ -21,8 +21,6 @@ package com.threerings.presents.dobj { -import com.threerings.util.StringBuilder; - /** * An object destroyed event is dispatched when an object has been removed * from the distributed object system. It can also be constructed to @@ -59,12 +57,5 @@ public class ObjectDestroyedEvent extends DEvent listener.objectDestroyed(this); } } - - // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void - { - buf.append("DESTROY:"); - super.toStringBuf(buf); - } } } diff --git a/src/as/com/threerings/presents/dobj/ObjectRemovedEvent.as b/src/as/com/threerings/presents/dobj/ObjectRemovedEvent.as index 2ed110bbc..0d2fb2fde 100644 --- a/src/as/com/threerings/presents/dobj/ObjectRemovedEvent.as +++ b/src/as/com/threerings/presents/dobj/ObjectRemovedEvent.as @@ -21,7 +21,7 @@ package com.threerings.presents.dobj { -import com.threerings.util.StringBuilder; +import com.threerings.util.Joiner; import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; @@ -99,11 +99,10 @@ public class ObjectRemovedEvent extends NamedEvent } // documentation inherited - override protected function toStringBuf (buf :StringBuilder) :void + override protected function toStringJoiner (j :Joiner) :void { - buf.append("OBJREM:"); - super.toStringBuf(buf); - buf.append(", oid=", _oid); + super.toStringJoiner(j); + j.add("oid", _oid); } protected var _oid :int; diff --git a/src/as/com/threerings/presents/dobj/OidList.as b/src/as/com/threerings/presents/dobj/OidList.as index 27bdd7bba..ed6f4484d 100644 --- a/src/as/com/threerings/presents/dobj/OidList.as +++ b/src/as/com/threerings/presents/dobj/OidList.as @@ -29,8 +29,6 @@ import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; import com.threerings.io.TypedArray; -import com.threerings.util.StringBuilder; - /** * An oid list is used to store lists of object ids. The list will not * allow duplicate ids. This class is not synchronized, with the @@ -127,11 +125,7 @@ public class OidList public function toString () :String { - var buf :StringBuilder = new StringBuilder(); - buf.append("{"); - buf.append(_oids.toString()); - buf.append("}"); - return buf.toString(); + return "{" + _oids.toString() + "}"; } private var _oids :TypedArray; diff --git a/src/as/com/threerings/presents/net/Credentials.as b/src/as/com/threerings/presents/net/Credentials.as index 4f5759913..507968863 100644 --- a/src/as/com/threerings/presents/net/Credentials.as +++ b/src/as/com/threerings/presents/net/Credentials.as @@ -23,67 +23,19 @@ package com.threerings.presents.net { import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; -import com.threerings.io.Streamable; +import com.threerings.io.SimpleStreamableObject; -public /* abstract */ class Credentials - implements Streamable +public /* abstract */ class Credentials extends SimpleStreamableObject { public function Credentials () { } // from interface Streamable - public function writeObject (out :ObjectOutputStream) :void - //throws IOError - { - // nada - } - - // from interface Streamable - public function readObject (ins :ObjectInputStream) :void + override public function readObject (ins :ObjectInputStream) :void //throws IOError { throw new Error(); // we never read Creds on the client } - - /* - // main - public function toString (joiner :Joiner = null) :String - { - if (joiner == null) { - return toString(new Joiner("ClassName")); - } - return joiner.add("baz", bit, "count", 33).toString(); - } - - // subclass - override public function toString (joiner :Joiner = null) :String - { - if (joiner != null) { - joiner.add("foo", bar); - } - return super.toString(joiner); - } - - - // ----- - - public function toString () :String - { - return join(new Joiner(this)).toString(); - } - - protected function join (joiner :Joiner) :Joiner - { - return joiner.add( - "baz", bit, "count", 33); - } - - override protected join (joiner :Joiner) :Joiner - { - return super.join(joiner).add( - "foo", bar); - } - */ } } diff --git a/src/as/com/threerings/presents/net/ServiceCreds.as b/src/as/com/threerings/presents/net/ServiceCreds.as index 45158e557..7398f2c64 100644 --- a/src/as/com/threerings/presents/net/ServiceCreds.as +++ b/src/as/com/threerings/presents/net/ServiceCreds.as @@ -26,6 +26,8 @@ import com.adobe.crypto.MD5; import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; +import com.threerings.util.Joiner; + /** * Extends the basic credentials to provide bureau-specific fields. */ @@ -60,9 +62,10 @@ public class ServiceCreds extends Credentials } // from Object - public function toString () :String + override protected function toStringJoiner (j :Joiner) :void { - return "[id=" + clientId + ", token=" + _authToken + "]"; + super.toStringJoiner(j); + j.add("token", _authToken); } /** diff --git a/src/as/com/threerings/presents/net/UsernamePasswordCreds.as b/src/as/com/threerings/presents/net/UsernamePasswordCreds.as index eb8cd5c72..9bcce611e 100644 --- a/src/as/com/threerings/presents/net/UsernamePasswordCreds.as +++ b/src/as/com/threerings/presents/net/UsernamePasswordCreds.as @@ -21,8 +21,8 @@ package com.threerings.presents.net { +import com.threerings.util.Joiner; import com.threerings.util.Name; -import com.threerings.util.StringBuilder; import com.threerings.io.ObjectInputStream; import com.threerings.io.ObjectOutputStream; @@ -55,26 +55,10 @@ public class UsernamePasswordCreds extends Credentials out.writeField(_password); } - // from Credentials - override public function readObject (ins :ObjectInputStream) :void + override protected function toStringJoiner (j :Joiner) :void { - _username = Name(ins.readObject()); - _password = (ins.readField(String) as String); - } - - // from Object - public function toString () :String - { - var buf :StringBuilder = new StringBuilder("["); - toStringBuf(buf); - buf.append("]"); - return buf.toString(); - } - - protected function toStringBuf (buf :StringBuilder) :void - { - buf.append("username=", _username); - buf.append(", password=", _password); + j.add("username", _username, "password", _password); + super.toStringJoiner(j); } protected var _username :Name; diff --git a/src/as/com/threerings/util/MessageBundle.as b/src/as/com/threerings/util/MessageBundle.as index 60af788f4..1c967f061 100644 --- a/src/as/com/threerings/util/MessageBundle.as +++ b/src/as/com/threerings/util/MessageBundle.as @@ -302,25 +302,24 @@ public class MessageBundle { args = Util.unfuckVarargs(args); - var buf :StringBuilder = new StringBuilder(); - buf.append(key, "|"); + var s :String = key + "|"; for (var ii :int = 0; ii < args.length; ii++) { if (ii > 0) { - buf.append("|"); + s += "|"; } var arg :String = String(args[ii]); for (var p :int = 0; p < arg.length; p++) { var ch :String = arg.charAt(p); if (ch == "|") { - buf.append("\\!"); + s += "\\!"; } else if (ch == "\\") { - buf.append("\\\\"); + s += "\\\\"; } else { - buf.append(ch); + s += ch; } } } - return buf.toString(); + return s; } /** @@ -404,19 +403,18 @@ public class MessageBundle return val; } - var buf :StringBuilder = new StringBuilder(); + var s :String = ""; for (var ii :int = 0; ii < val.length; ii++) { var ch :String = val.charAt(ii); if (ch != "\\" || ii == val.length-1) { - buf.append(ch); + s += ch; } else { // look at the next character ch = val.charAt(++ii); - buf.append((ch == "!") ? "|" : ch); + s += (ch == "!") ? "|" : ch; } } - - return buf.toString(); + return s; } /** The message manager via whom we'll resolve fully qualified