From d0cfcca2fadddba279a8f99eb9762e0bab88ab72 Mon Sep 17 00:00:00 2001 From: ray Date: Mon, 21 Aug 2006 21:31:44 +0000 Subject: [PATCH] Don't do anything if there are no observers to notify. Shrink our working array if it's much larger than it needs to be. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1888 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/util/ObserverList.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/java/com/samskivert/util/ObserverList.java b/src/java/com/samskivert/util/ObserverList.java index c84d0c21..deb8d593 100644 --- a/src/java/com/samskivert/util/ObserverList.java +++ b/src/java/com/samskivert/util/ObserverList.java @@ -178,13 +178,17 @@ public class ObserverList extends ArrayList @SuppressWarnings("unchecked") public void apply (ObserverOp obop) { + int ocount = size(); + if (ocount == 0) { + return; + } if (_policy == SAFE_IN_ORDER_NOTIFY) { // if we have to notify our observers in order, we need to // create a snapshot of the observer array at the time we // start the notification to ensure that modifications to the // array during notification don't hose us - int ocount = size(); - if (_snap == null || _snap.length < ocount) { + if (_snap == null || _snap.length < ocount || + _snap.length > (ocount << 3)) { _snap = (T[])new Object[ocount]; } Object[] obs = toArray(_snap); @@ -197,7 +201,6 @@ public class ObserverList extends ArrayList Arrays.fill(_snap, null); } else if (_policy == FAST_UNSAFE_NOTIFY) { - int ocount = size(); for (int ii = ocount-1; ii >= 0; ii--) { if (!checkedApply(obop, get(ii))) { remove(ii);