Buffer allocation optimizations in PacketWriter
Misc string cleanup
This commit is contained in:
parent
b7ea90d3af
commit
3da4aa9efa
5 changed files with 116 additions and 44 deletions
|
|
@ -1055,7 +1055,7 @@ namespace Server.Commands
|
|||
break;
|
||||
}
|
||||
|
||||
if ( line == null || line.Length == 0 )
|
||||
if ( string.IsNullOrEmpty( line ) )
|
||||
return null;
|
||||
|
||||
DecorationList list = new DecorationList();
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace Server.Guilds
|
|||
AddButton( 40, 251, 0x4B9, 0x4BA, 4, GumpButtonType.Reply, 0 ); //Charter Edit button
|
||||
|
||||
s = guild.Website;
|
||||
if( s == null || s == "" )
|
||||
if( string.IsNullOrEmpty( s ) )
|
||||
s = "Guild website not yet set.";
|
||||
AddHtml( 65, 306, 480, 30, s, true, false );
|
||||
if( isLeader )
|
||||
|
|
|
|||
|
|
@ -4666,7 +4666,7 @@ namespace Server
|
|||
|
||||
text = regArgs.Speech;
|
||||
|
||||
if( text == null || text.Length == 0 )
|
||||
if( string.IsNullOrEmpty( text ) )
|
||||
return;
|
||||
|
||||
if( m_Hears == null )
|
||||
|
|
|
|||
|
|
@ -207,7 +207,19 @@ namespace Server.Network
|
|||
value = String.Empty;
|
||||
}
|
||||
|
||||
byte[] buffer = Encoding.ASCII.GetBytes( value );
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + size );
|
||||
|
||||
if ( length >= size )
|
||||
m_Stream.Position += Encoding.ASCII.GetBytes( value, 0, size, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
else
|
||||
{
|
||||
Encoding.ASCII.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += size;
|
||||
}
|
||||
|
||||
/*byte[] buffer = Encoding.ASCII.GetBytes( value );
|
||||
|
||||
if ( buffer.Length >= size )
|
||||
{
|
||||
|
|
@ -217,7 +229,7 @@ namespace Server.Network
|
|||
{
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
Fill( size - buffer.Length );
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -231,10 +243,17 @@ namespace Server.Network
|
|||
value = String.Empty;
|
||||
}
|
||||
|
||||
byte[] buffer = Encoding.ASCII.GetBytes( value );
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + length + 1 );
|
||||
|
||||
Encoding.ASCII.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += length + 1;
|
||||
|
||||
/*byte[] buffer = Encoding.ASCII.GetBytes( value );
|
||||
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
m_Stream.WriteByte( 0 );
|
||||
m_Stream.WriteByte( 0 );*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -248,13 +267,20 @@ namespace Server.Network
|
|||
value = String.Empty;
|
||||
}
|
||||
|
||||
byte[] buffer = Encoding.Unicode.GetBytes( value );
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + ( ( length + 1 ) * 2 ) );
|
||||
|
||||
m_Stream.Position += Encoding.Unicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += 2;
|
||||
|
||||
/*byte[] buffer = Encoding.Unicode.GetBytes( value );
|
||||
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
|
||||
m_Buffer[0] = 0;
|
||||
m_Buffer[1] = 0;
|
||||
m_Stream.Write( m_Buffer, 0, 2 );
|
||||
m_Stream.Write( m_Buffer, 0, 2 );*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -270,6 +296,20 @@ namespace Server.Network
|
|||
|
||||
size *= 2;
|
||||
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + size );
|
||||
|
||||
if ( ( length * 2 ) >= size )
|
||||
m_Stream.Position += Encoding.Unicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
else
|
||||
{
|
||||
Encoding.Unicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += size;
|
||||
}
|
||||
|
||||
/*size *= 2;
|
||||
|
||||
byte[] buffer = Encoding.Unicode.GetBytes( value );
|
||||
|
||||
if ( buffer.Length >= size )
|
||||
|
|
@ -280,7 +320,7 @@ namespace Server.Network
|
|||
{
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
Fill( size - buffer.Length );
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -294,13 +334,20 @@ namespace Server.Network
|
|||
value = String.Empty;
|
||||
}
|
||||
|
||||
byte[] buffer = Encoding.BigEndianUnicode.GetBytes( value );
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + ( ( length + 1 ) * 2 ) );
|
||||
|
||||
m_Stream.Position += Encoding.BigEndianUnicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += 2;
|
||||
|
||||
/*byte[] buffer = Encoding.BigEndianUnicode.GetBytes( value );
|
||||
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
|
||||
m_Buffer[0] = 0;
|
||||
m_Buffer[1] = 0;
|
||||
m_Stream.Write( m_Buffer, 0, 2 );
|
||||
m_Stream.Write( m_Buffer, 0, 2 );*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -316,6 +363,20 @@ namespace Server.Network
|
|||
|
||||
size *= 2;
|
||||
|
||||
int length = value.Length;
|
||||
|
||||
m_Stream.SetLength( m_Stream.Length + size );
|
||||
|
||||
if ( ( length * 2 ) >= size )
|
||||
m_Stream.Position += Encoding.BigEndianUnicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
else
|
||||
{
|
||||
Encoding.BigEndianUnicode.GetBytes( value, 0, length, m_Stream.GetBuffer(), (int)m_Stream.Position );
|
||||
m_Stream.Position += size;
|
||||
}
|
||||
|
||||
/*size *= 2;
|
||||
|
||||
byte[] buffer = Encoding.BigEndianUnicode.GetBytes( value );
|
||||
|
||||
if ( buffer.Length >= size )
|
||||
|
|
@ -326,7 +387,7 @@ namespace Server.Network
|
|||
{
|
||||
m_Stream.Write( buffer, 0, buffer.Length );
|
||||
Fill( size - buffer.Length );
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -477,13 +477,16 @@ namespace Server.Network
|
|||
{
|
||||
string name = info.Crafter.Name;
|
||||
|
||||
if ( name == null ) name = "";
|
||||
|
||||
int length = (ushort)name.Length;
|
||||
|
||||
m_Stream.Write( (int) -3 );
|
||||
m_Stream.Write( (ushort) length );
|
||||
m_Stream.WriteAsciiFixed( name, length );
|
||||
|
||||
if ( name == null )
|
||||
m_Stream.Write( (ushort) 0 );
|
||||
else
|
||||
{
|
||||
int length = name.Length;
|
||||
m_Stream.Write( (ushort) length );
|
||||
m_Stream.WriteAsciiFixed( name, length );
|
||||
}
|
||||
}
|
||||
|
||||
if ( info.Unidentified )
|
||||
|
|
@ -695,12 +698,14 @@ namespace Server.Network
|
|||
|
||||
string question = menu.Question;
|
||||
|
||||
if ( question == null ) question = "";
|
||||
|
||||
int questionLength = (byte)question.Length;
|
||||
|
||||
m_Stream.Write( (byte) questionLength );
|
||||
m_Stream.WriteAsciiFixed( question, questionLength );
|
||||
if ( question == null )
|
||||
m_Stream.Write( (byte) 0 );
|
||||
else
|
||||
{
|
||||
int questionLength = question.Length;
|
||||
m_Stream.Write( (byte) questionLength );
|
||||
m_Stream.WriteAsciiFixed( question, questionLength );
|
||||
}
|
||||
|
||||
ItemListEntry[] entries = menu.Entries;
|
||||
|
||||
|
|
@ -717,12 +722,14 @@ namespace Server.Network
|
|||
|
||||
string name = e.Name;
|
||||
|
||||
if ( name == null ) name = "";
|
||||
|
||||
int nameLength = (byte)name.Length;
|
||||
|
||||
m_Stream.Write( (byte) nameLength );
|
||||
m_Stream.WriteAsciiFixed( name, nameLength );
|
||||
if ( name == null )
|
||||
m_Stream.Write( (byte) 0 );
|
||||
else
|
||||
{
|
||||
int nameLength = name.Length;
|
||||
m_Stream.Write( (byte) nameLength );
|
||||
m_Stream.WriteAsciiFixed( name, nameLength );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -738,12 +745,14 @@ namespace Server.Network
|
|||
|
||||
string question = menu.Question;
|
||||
|
||||
if ( question == null ) question = "";
|
||||
|
||||
int questionLength = (byte)question.Length;
|
||||
|
||||
m_Stream.Write( (byte) questionLength );
|
||||
m_Stream.WriteAsciiFixed( question, questionLength );
|
||||
if ( question == null )
|
||||
m_Stream.Write( (byte) 0 );
|
||||
else
|
||||
{
|
||||
int questionLength = question.Length;
|
||||
m_Stream.Write( (byte) questionLength );
|
||||
m_Stream.WriteAsciiFixed( question, questionLength );
|
||||
}
|
||||
|
||||
string[] answers = menu.Answers;
|
||||
|
||||
|
|
@ -757,12 +766,14 @@ namespace Server.Network
|
|||
|
||||
string answer = answers[i];
|
||||
|
||||
if ( answer == null ) answer = "";
|
||||
|
||||
int answerLength = (byte)answer.Length;
|
||||
|
||||
m_Stream.Write( (byte) answerLength );
|
||||
m_Stream.WriteAsciiFixed( answer, answerLength );
|
||||
if ( answer == null )
|
||||
m_Stream.Write( (byte) 0 );
|
||||
else
|
||||
{
|
||||
int answerLength = answer.Length;
|
||||
m_Stream.Write( (byte) answerLength );
|
||||
m_Stream.WriteAsciiFixed( answer, answerLength );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2889,7 +2900,7 @@ namespace Server.Network
|
|||
{
|
||||
public UnicodeMessage( Serial serial, int graphic, MessageType type, int hue, int font, string lang, string name, string text ) : base( 0xAE )
|
||||
{
|
||||
if ( lang == null || lang == "" ) lang = "ENU";
|
||||
if ( string.IsNullOrEmpty( lang ) ) lang = "ENU";
|
||||
if ( name == null ) name = "";
|
||||
if ( text == null ) text = "";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue