From a8acb6bd9d9b085b39f48c6169989d2250c0eefe Mon Sep 17 00:00:00 2001 From: krrios Date: Wed, 25 Apr 2007 01:06:43 +0000 Subject: [PATCH] removed initial capacity to List and ArrayList where inappropriate --- Scripts/Engines/AI/Creature/BaseCreature.cs | 2 +- Scripts/Multis/BaseHouse.cs | 2 +- Server/Item.cs | 10 +- Server/Items/Container.cs | 5 +- Server/Mobile.cs | 27 ++-- Server/Race.cs | 2 +- Server/Serialization.cs | 162 +++++++++----------- 7 files changed, 100 insertions(+), 110 deletions(-) diff --git a/Scripts/Engines/AI/Creature/BaseCreature.cs b/Scripts/Engines/AI/Creature/BaseCreature.cs index 5884a8508..fc926ae03 100644 --- a/Scripts/Engines/AI/Creature/BaseCreature.cs +++ b/Scripts/Engines/AI/Creature/BaseCreature.cs @@ -672,7 +672,7 @@ namespace Server.Mobiles public virtual void AddPetFriend( Mobile m ) { if ( m_Friends == null ) - m_Friends = new List( 8 ); + m_Friends = new List(); m_Friends.Add( m ); } diff --git a/Scripts/Multis/BaseHouse.cs b/Scripts/Multis/BaseHouse.cs index 5bac5692f..befe2895c 100644 --- a/Scripts/Multis/BaseHouse.cs +++ b/Scripts/Multis/BaseHouse.cs @@ -83,7 +83,7 @@ namespace Server.Multis if ( (acct.LastLogin + TimeSpan.FromDays( 90.0 )) < DateTime.Now ) return DecayType.Condemned; - List allHouses = new List( 2 ); + List allHouses = new List(); for ( int i = 0; i < acct.Length; ++i ) { diff --git a/Server/Item.cs b/Server/Item.cs index 17f39a6ff..e42d3248b 100644 --- a/Server/Item.cs +++ b/Server/Item.cs @@ -560,8 +560,7 @@ namespace Server public class Item : IEntity, IHued, IComparable, ISerializable { - //public static readonly EmptyArrayList EmptyItems = new EmptyArrayList(); - public static readonly List EmptyItems = new List( 0 ); + public static readonly List EmptyItems = new List(); public int CompareTo( IEntity other ) { @@ -802,15 +801,16 @@ namespace Server { Container cont = this as Container; - if ( cont.m_Items == null ) - cont.m_Items = new List( 4 ); + if ( cont.m_Items == null ) { + cont.m_Items = new List(); + } return cont.m_Items; } CompactInfo info = AcquireCompactInfo(); - info.m_Items = new List( 4 ); + info.m_Items = new List(); return info.m_Items; } diff --git a/Server/Items/Container.cs b/Server/Items/Container.cs index f505daa76..57cda5142 100644 --- a/Server/Items/Container.cs +++ b/Server/Items/Container.cs @@ -1645,8 +1645,9 @@ namespace Server.Items if ( !contains ) { - if ( m_Openers == null ) - m_Openers = new List( 4 ); + if ( m_Openers == null ) { + m_Openers = new List(); + } m_Openers.Add( to ); } diff --git a/Server/Mobile.cs b/Server/Mobile.cs index aad7aa34e..b4d182459 100644 --- a/Server/Mobile.cs +++ b/Server/Mobile.cs @@ -919,8 +919,9 @@ namespace Server public virtual void AddResistanceMod( ResistanceMod toAdd ) { - if( m_ResistMods == null ) - m_ResistMods = new List( 2 ); + if ( m_ResistMods == null ) { + m_ResistMods = new List(); + } m_ResistMods.Add( toAdd ); UpdateResistances(); @@ -1465,7 +1466,7 @@ namespace Server public bool BeginAction( object toLock ) { if ( _actions == null ) { - _actions = new List( 2 ); + _actions = new List(); _actions.Add( toLock ); @@ -9490,10 +9491,10 @@ namespace Server { m_Region = Map.Internal.DefaultRegion; m_Serial = serial; - m_Aggressors = new List( 1 ); - m_Aggressed = new List( 1 ); + m_Aggressors = new List(); + m_Aggressed = new List(); m_NextSkillTime = DateTime.MinValue; - m_DamageEntries = new List( 1 ); + m_DamageEntries = new List(); Type ourType = this.GetType(); m_TypeRef = World.m_MobileTypes.IndexOf( ourType ); @@ -9529,16 +9530,16 @@ namespace Server m_StatCap = 225; m_FollowersMax = 5; m_Skills = new Skills( this ); - m_Items = new List( 1 ); - m_StatMods = new List( 1 ); - m_SkillMods = new List( 1 ); + m_Items = new List(); + m_StatMods = new List(); + m_SkillMods = new List(); Map = Map.Internal; m_AutoPageNotify = true; - m_Aggressors = new List( 1 ); - m_Aggressed = new List( 1 ); + m_Aggressors = new List(); + m_Aggressed = new List(); m_Virtues = new VirtueInfo(); - m_Stabled = new List( 1 ); - m_DamageEntries = new List( 1 ); + m_Stabled = new List(); + m_DamageEntries = new List(); m_NextSkillTime = DateTime.MinValue; m_CreationTime = DateTime.Now; diff --git a/Server/Race.cs b/Server/Race.cs index 49f0c2b13..7df595aad 100644 --- a/Server/Race.cs +++ b/Server/Race.cs @@ -37,7 +37,7 @@ namespace Server public static Race Human { get { return m_Races[0]; } } public static Race Elf { get { return m_Races[1]; } } - private static List m_AllRaces = new List( 2 ); + private static List m_AllRaces = new List(); public static List AllRaces { get { return m_AllRaces; } } diff --git a/Server/Serialization.cs b/Server/Serialization.cs index a502e4bb1..464d0edd1 100644 --- a/Server/Serialization.cs +++ b/Server/Serialization.cs @@ -999,153 +999,141 @@ namespace Server { int count = ReadInt(); - ArrayList list = new ArrayList( count ); + if ( count > 0 ) { + ArrayList list = new ArrayList( count ); - for( int i = 0; i < count; ++i ) - { - Item item = ReadItem(); + for ( int i = 0; i < count; ++i ) { + Item item = ReadItem(); - if( item != null ) - list.Add( item ); + if ( item != null ) { + list.Add( item ); + } + } + + return list; + } else { + return new ArrayList(); } - - return list; } public override ArrayList ReadMobileList() { int count = ReadInt(); - ArrayList list = new ArrayList( count ); + if ( count > 0 ) { + ArrayList list = new ArrayList( count ); - for( int i = 0; i < count; ++i ) - { - Mobile m = ReadMobile(); + for ( int i = 0; i < count; ++i ) { + Mobile m = ReadMobile(); - if( m != null ) - list.Add( m ); + if ( m != null ) { + list.Add( m ); + } + } + + return list; + } else { + return new ArrayList(); } - - return list; } public override ArrayList ReadGuildList() { int count = ReadInt(); - ArrayList list = new ArrayList( count ); + if ( count > 0 ) { + ArrayList list = new ArrayList( count ); - for( int i = 0; i < count; ++i ) - { - BaseGuild g = ReadGuild(); + for ( int i = 0; i < count; ++i ) { + BaseGuild g = ReadGuild(); - if( g != null ) - list.Add( g ); + if ( g != null ) { + list.Add( g ); + } + } + + return list; + } else { + return new ArrayList(); } - - return list; } public override List ReadStrongItemList() { - int count = ReadInt(); - - List list = new List( count ); - - for( int i = 0; i < count; ++i ) - { - Item item = ReadItem(); - - if( item != null ) - list.Add( item ); - } - - return list; + return ReadStrongItemList(); } public override List ReadStrongItemList() { int count = ReadInt(); - List list = new List( count ); + if ( count > 0 ) { + List list = new List( count ); - for( int i = 0; i < count; ++i ) - { - T item = ReadItem() as T; + for ( int i = 0; i < count; ++i ) { + T item = ReadItem() as T; - if( item != null ) - list.Add( item ); + if ( item != null ) { + list.Add( item ); + } + } + + return list; + } else { + return new List(); } - - return list; } public override List ReadStrongMobileList() { - int count = ReadInt(); - - List list = new List( count ); - - for( int i = 0; i < count; ++i ) - { - Mobile m = ReadMobile(); - - if( m != null ) - list.Add( m ); - } - - return list; + return ReadStrongMobileList(); } public override List ReadStrongMobileList() { int count = ReadInt(); - List list = new List( count ); + if ( count > 0 ) { + List list = new List( count ); - for( int i = 0; i < count; ++i ) - { - T m = ReadMobile() as T; + for ( int i = 0; i < count; ++i ) { + T m = ReadMobile() as T; - if( m != null ) - list.Add( m ); + if ( m != null ) { + list.Add( m ); + } + } + + return list; + } else { + return new List(); } - - return list; } public override List ReadStrongGuildList() { - int count = ReadInt(); - - List list = new List( count ); - - for( int i = 0; i < count; ++i ) - { - BaseGuild g = ReadGuild(); - - if( g != null ) - list.Add( g ); - } - - return list; + return ReadStrongGuildList(); } public override List ReadStrongGuildList() { int count = ReadInt(); - List list = new List( count ); + if ( count > 0 ) { + List list = new List( count ); - for( int i = 0; i < count; ++i ) - { - T g = ReadGuild() as T; + for ( int i = 0; i < count; ++i ) { + T g = ReadGuild() as T; - if( g != null ) - list.Add( g ); + if ( g != null ) { + list.Add( g ); + } + } + + return list; + } else { + return new List(); } - - return list; } public override bool End()