System.UnSafeCharBuffer

namespace System
{
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]
internal struct UnSafeCharBuffer
{
private char* m_buffer;
private int m_totalSize;
private int m_length;
public UnSafeCharBuffer(char* buffer,int bufferSize)
{
//.maxstack  8
//IL_0000:  ldarg.0
//IL_0001:  ldarg.1
//IL_0002:  stfld      char* System.UnSafeCharBuffer::m_buffer
//IL_0007:  ldarg.0
//IL_0008:  ldarg.2
//IL_0009:  stfld      int32 System.UnSafeCharBuffer::m_totalSize
//IL_000e:  ldarg.0
//IL_000f:  ldc.i4.0
//IL_0010:  stfld      int32 System.UnSafeCharBuffer::m_length
//IL_0015:  ret
            this.m_buffer = buffer;
            this.m_totalSize = bufferSize;
            this.m_length = 0;
}
public void AppendString(string stringToAppend)
{
//.maxstack  4
            //.locals init (char* V_0,                  
//string pinned V_1)
//IL_0000:  ldarg.1
//IL_0001:  call       bool System.String::IsNullOrEmpty(string)
//IL_0006:  brfalse.s  IL_0009
//IL_0008:  ret
//IL_0009:  ldarg.0
//IL_000a:  ldfld      int32 System.UnSafeCharBuffer::m_totalSize
//IL_000f:  ldarg.0
//IL_0010:  ldfld      int32 System.UnSafeCharBuffer::m_length
//IL_0015:  sub
//IL_0016:  ldarg.1
//IL_0017:  callvirt   instance int32 System.String::get_Length()
//IL_001c:  bge.s      IL_0024
//IL_001e:  newobj     instance void System.IndexOutOfRangeException::.ctor()
//IL_0023:  throw
            //IL_0024:  ldarg.1                     
//IL_0025:  stloc.1
//IL_0026:  ldloc.1
//IL_0027:  conv.i
//IL_0028:  dup
//IL_0029:  brfalse.s  IL_0031
//IL_002b:  call       int32 System.Runtime.CompilerServices.RuntimeHelpers::get_OffsetToStringData()
//IL_0030:  add
//IL_0031:  stloc.0
//IL_0032:  ldloc.0
//IL_0033:  ldarg.0
//IL_0034:  ldfld      char* System.UnSafeCharBuffer::m_buffer
//IL_0039:  ldarg.0
//IL_003a:  ldfld      int32 System.UnSafeCharBuffer::m_length
//IL_003f:  conv.i
//IL_0040:  ldc.i4.2
//IL_0041:  mul
//IL_0042:  add
//IL_0043:  ldarg.1
//IL_0044:  callvirt   instance int32 System.String::get_Length()
//IL_0049:  ldc.i4.2
//IL_004a:  mul
//IL_004b:  call       void System.Buffer::memcpyimpl(uint8*,
//uint8*,
//int32)
//IL_0050:  ldnull
//IL_0051:  stloc.1
//IL_0052:  ldarg.0
//IL_0053:  dup
//IL_0054:  ldfld      int32 System.UnSafeCharBuffer::m_length
//IL_0059:  ldarg.1
//IL_005a:  callvirt   instance int32 System.String::get_Length()
//IL_005f:  add
//IL_0060:  stfld      int32 System.UnSafeCharBuffer::m_length
//IL_0065:  ret            
            if(!string.IsNullOrEmpty(stringToAppend))
            {
                if((this.m_totalSize-this.m_length)>=stringToAppend.Length)
                {
                    //IL_0024
                    V_1 = stringToAppend;
                    fixed (char* V_0 = stringToAppend)
                    {
                        System.Buffer.memcpyimpl(V_0, this.m_buffer + this.m_length * 2, stringToAppend.Length * 2);
                    }                    
                    //IL_0050
                    this.m_length=this.m_length+stringToAppend.Length;
                }
                else
                {
                    throw new System.IndexOutOfRangeException();
                }
            }
}
        public int Length
        {
            get
            {
                ;
            }            
            //.get instance int32 System.UnSafeCharBuffer::get_Length()
        }
public int get_Length()
{
//.maxstack  8
//IL_0000:  ldarg.0
//IL_0001:  ldfld      int32 System.UnSafeCharBuffer::m_length
//IL_0006:  ret
            return this.m_length;
}
}
}

posted @ 2010-08-28 21:23  Aegis  阅读(259)  评论(0编辑  收藏  举报