You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by di...@apache.org on 2010/05/02 01:08:42 UTC
svn commit: r940122 -
/lucene/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
Author: digy
Date: Sat May 1 23:08:42 2010
New Revision: 940122
URL: http://svn.apache.org/viewvc?rev=940122&view=rev
Log:
LUCENENET-365 Significant performance improvement for CompressionTools
Modified:
lucene/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
Modified: lucene/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/src/Lucene.Net/SupportClass.cs?rev=940122&r1=940121&r2=940122&view=diff
==============================================================================
--- lucene/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs (original)
+++ lucene/lucene.net/trunk/C#/src/Lucene.Net/SupportClass.cs Sat May 1 23:08:42 2010
@@ -2176,74 +2176,120 @@ public class SupportClass
public class Inflater
{
- object inflaterInstance = null;
- Type inflaterType;
+ delegate void SetInputDelegate(byte[] buffer);
+ delegate bool GetIsFinishedDelegate();
+ delegate int InflateDelegate(byte[] buffer);
+
+ SetInputDelegate setInputMethod;
+ GetIsFinishedDelegate getIsFinishedMethod;
+ InflateDelegate inflateMethod;
internal Inflater(object inflaterInstance)
{
- this.inflaterInstance = inflaterInstance;
- this.inflaterType = inflaterInstance.GetType();
+ Type type = inflaterInstance.GetType();
+
+ setInputMethod = (SetInputDelegate)Delegate.CreateDelegate(
+ typeof(SetInputDelegate),
+ inflaterInstance,
+ type.GetMethod("SetInput", new Type[] { typeof(byte[]) }));
+
+ getIsFinishedMethod = (GetIsFinishedDelegate)Delegate.CreateDelegate(
+ typeof(GetIsFinishedDelegate),
+ inflaterInstance,
+ type.GetMethod("get_IsFinished", Type.EmptyTypes));
+
+ inflateMethod = (InflateDelegate)Delegate.CreateDelegate(
+ typeof(InflateDelegate),
+ inflaterInstance,
+ type.GetMethod("Inflate", new Type[] { typeof(byte[]) }));
}
public void SetInput(byte[] buffer)
{
- inflaterType.InvokeMember("SetInput", System.Reflection.BindingFlags.InvokeMethod, null, inflaterInstance, new object[] { buffer });
+ setInputMethod(buffer);
}
public bool IsFinished
{
- get
- {
- return (bool)inflaterType.InvokeMember("get_IsFinished", System.Reflection.BindingFlags.InvokeMethod, null, inflaterInstance, null);
- }
+ get { return getIsFinishedMethod(); }
}
public int Inflate(byte[] buffer)
{
- return (int)inflaterType.InvokeMember("Inflate", System.Reflection.BindingFlags.InvokeMethod, null, inflaterInstance, new object[] { buffer });
+ return inflateMethod(buffer);
}
}
public class Deflater
{
- public const int BEST_COMPRESSION = 9;
+ delegate void SetLevelDelegate(int level);
+ delegate void SetInputDelegate(byte[] input, int offset, int count);
+ delegate void FinishDelegate();
+ delegate bool GetIsFinishedDelegate();
+ delegate int DeflateDelegate(byte[] output);
+
+ SetLevelDelegate setLevelMethod;
+ SetInputDelegate setInputMethod;
+ FinishDelegate finishMethod;
+ GetIsFinishedDelegate getIsFinishedMethod;
+ DeflateDelegate deflateMethod;
- object deflaterInstance = null;
- Type deflaterType;
+ public const int BEST_COMPRESSION = 9;
internal Deflater(object deflaterInstance)
{
- this.deflaterInstance = deflaterInstance;
- this.deflaterType = deflaterInstance.GetType();
+ Type type = deflaterInstance.GetType();
+
+ setLevelMethod = (SetLevelDelegate)Delegate.CreateDelegate(
+ typeof(SetLevelDelegate),
+ deflaterInstance,
+ type.GetMethod("SetLevel", new Type[] { typeof(int) }));
+
+ setInputMethod = (SetInputDelegate)Delegate.CreateDelegate(
+ typeof(SetInputDelegate),
+ deflaterInstance,
+ type.GetMethod("SetInput", new Type[] { typeof(byte[]), typeof(int), typeof(int) }));
+
+ finishMethod = (FinishDelegate)Delegate.CreateDelegate(
+ typeof(FinishDelegate),
+ deflaterInstance,
+ type.GetMethod("Finish", Type.EmptyTypes));
+
+ getIsFinishedMethod = (GetIsFinishedDelegate)Delegate.CreateDelegate(
+ typeof(GetIsFinishedDelegate),
+ deflaterInstance,
+ type.GetMethod("get_IsFinished", Type.EmptyTypes));
+
+ deflateMethod = (DeflateDelegate)Delegate.CreateDelegate(
+ typeof(DeflateDelegate),
+ deflaterInstance,
+ type.GetMethod("Deflate", new Type[] { typeof(byte[]) }));
}
public void SetLevel(int level)
{
- deflaterType.InvokeMember("SetLevel", System.Reflection.BindingFlags.InvokeMethod, null, deflaterInstance, new object[] { level });
+ setLevelMethod(level);
}
public void SetInput(byte[] input, int offset, int count)
{
- deflaterType.InvokeMember("SetInput", System.Reflection.BindingFlags.InvokeMethod, null, deflaterInstance, new object[] { input,offset,count });
+ setInputMethod(input, offset, count);
}
public void Finish()
{
- deflaterType.InvokeMember("Finish", System.Reflection.BindingFlags.InvokeMethod, null, deflaterInstance, null);
+ finishMethod();
}
public bool IsFinished
{
- get
- {
- return (bool)deflaterType.InvokeMember("get_IsFinished", System.Reflection.BindingFlags.InvokeMethod, null, deflaterInstance, null); ;
- }
+ get { return getIsFinishedMethod(); }
}
public int Deflate(byte[] output)
{
- return (int)deflaterType.InvokeMember("Deflate", System.Reflection.BindingFlags.InvokeMethod, null, deflaterInstance, new object[] { output });
+ return deflateMethod(output);
}
}
}