12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- namespace PaintDotNet
- {
- /// <summary>
- /// Provides access to a cached group of boxed, commonly used constants.
- /// This helps to avoid boxing overhead, much of which consists of transferring
- /// the item to the heap. Unboxing, on the other hand, is quite cheap.
- /// This is commonly used to pass index values to worker threads.
- /// </summary>
- public sealed class BoxedConstants
- {
- private static object[] boxedInt32 = new object[1024];
- private static object boxedTrue = (object)true;
- private static object boxedFalse = (object)false;
- public static object GetInt32(int value)
- {
- if (value >= boxedInt32.Length || value < 0)
- {
- return (object)value;
- }
- if (boxedInt32[value] == null)
- {
- boxedInt32[value] = (object)value;
- }
- return boxedInt32[value];
- }
- public static object GetBoolean(bool value)
- {
- return value ? boxedTrue : boxedFalse;
- }
- static BoxedConstants()
- {
- }
- private BoxedConstants()
- {
- }
- }
- }
|