Use new string(sbyte*) instead of Marshal.PtrToStringAnsi to increase performance when calling GetString to retrieve the list of available extensions.

This commit is contained in:
the_fiddler 2009-11-03 12:59:25 +00:00
parent eb92aa8223
commit 18109103e3
5 changed files with 8 additions and 8 deletions

View file

@ -531,7 +531,7 @@ namespace Bind.Structures
if (f.ReturnType.CurrentType.ToLower().Contains("void"))
f.Body.Add(String.Format("{0};", method_call));
else if (ReturnType.CurrentType.ToLower().Contains("string"))
f.Body.Add(String.Format("{0} {1} = Marshal.PtrToStringAnsi({2});",
f.Body.Add(String.Format("{0} {1} = null; unsafe {{ {1} = new string((sbyte*){2}); }}",
ReturnType.QualifiedType, "retval", method_call));
else
f.Body.Add(String.Format("{0} {1} = {2};", f.ReturnType.QualifiedType, "retval", method_call));
@ -551,7 +551,7 @@ namespace Bind.Structures
if (f.ReturnType.CurrentType.ToLower().Contains("void"))
f.Body.Add(String.Format("{0};", f.CallString()));
else if (ReturnType.CurrentType.ToLower().Contains("string"))
f.Body.Add(String.Format("return System.Runtime.InteropServices.Marshal.PtrToStringAnsi({0});",
f.Body.Add(String.Format("unsafe {{ return new string((sbyte*){0}); }}",
f.CallString()));
else
f.Body.Add(String.Format("return {0};", f.CallString()));

View file

@ -2599,7 +2599,7 @@ namespace OpenTK.Graphics.ES10
using (new ErrorHelper(GraphicsContext.CurrentContext))
{
#endif
return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Delegates.glGetString((OpenTK.Graphics.ES10.All)name));
unsafe { return new string((sbyte*)Delegates.glGetString((OpenTK.Graphics.ES10.All)name)); }
#if DEBUG
}
#endif

View file

@ -5018,7 +5018,7 @@ namespace OpenTK.Graphics.ES11
using (new ErrorHelper(GraphicsContext.CurrentContext))
{
#endif
return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Delegates.glGetString((OpenTK.Graphics.ES11.All)name));
unsafe { return new string((sbyte*)Delegates.glGetString((OpenTK.Graphics.ES11.All)name)); }
#if DEBUG
}
#endif

View file

@ -8202,7 +8202,7 @@ namespace OpenTK.Graphics.ES20
using (new ErrorHelper(GraphicsContext.CurrentContext))
{
#endif
return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Delegates.glGetString((OpenTK.Graphics.ES20.StringName)name));
unsafe { return new string((sbyte*)Delegates.glGetString((OpenTK.Graphics.ES20.StringName)name)); }
#if DEBUG
}
#endif

View file

@ -49901,7 +49901,7 @@ namespace OpenTK.Graphics.OpenGL
using (new ErrorHelper(GraphicsContext.CurrentContext))
{
#endif
return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Delegates.glGetString((OpenTK.Graphics.OpenGL.StringName)name));
unsafe { return new string((sbyte*)Delegates.glGetString((OpenTK.Graphics.OpenGL.StringName)name)); }
#if DEBUG
}
#endif
@ -49924,7 +49924,7 @@ namespace OpenTK.Graphics.OpenGL
using (new ErrorHelper(GraphicsContext.CurrentContext))
{
#endif
return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Delegates.glGetStringi((OpenTK.Graphics.OpenGL.StringName)name, (UInt32)index));
unsafe { return new string((sbyte*)Delegates.glGetStringi((OpenTK.Graphics.OpenGL.StringName)name, (UInt32)index)); }
#if DEBUG
}
#endif
@ -49948,7 +49948,7 @@ namespace OpenTK.Graphics.OpenGL
using (new ErrorHelper(GraphicsContext.CurrentContext))
{
#endif
return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Delegates.glGetStringi((OpenTK.Graphics.OpenGL.StringName)name, (UInt32)index));
unsafe { return new string((sbyte*)Delegates.glGetStringi((OpenTK.Graphics.OpenGL.StringName)name, (UInt32)index)); }
#if DEBUG
}
#endif