public void ToString(StringBuilder sb) { sb.Append(Count).Append(" items: ["); bool first = true; ObjRefStore[] table = this.table; for (int a = table.Length; a-- > 0;) { ObjRefStore entry = table[a]; while (entry != null) { if (first) { first = false; } else { sb.Append(','); } StringBuilderUtil.AppendPrintable(sb, entry); entry = entry.NextEntry; } } sb.Append(']'); }
public void ToString(StringBuilder sb) { sb.Append(Count).Append(" items: ["); bool first = true; Tuple2KeyEntry <Key1, Key2, V>[] table = this.table; for (int a = table.Length; a-- > 0;) { Tuple2KeyEntry <Key1, Key2, V> entry = table[a]; while (entry != null) { if (first) { first = false; } else { sb.Append(','); } StringBuilderUtil.AppendPrintable(sb, entry); entry = entry.GetNextEntry(); } } sb.Append(']'); }
public void ToString(StringBuilder sb) { sb.Append('('); StringBuilderUtil.AppendPrintable(sb, Key); sb.Append(','); StringBuilderUtil.AppendPrintable(sb, Value); sb.Append(')'); }
public void ToString(StringBuilder sb, int tabCount) { ToStringIntern(sb, new PrintableDelegateWrapper(new PrintableDelegate(delegate(StringBuilder sb2) { sb.Append(Environment.NewLine); StringBuilderUtil.AppendTabs(sb, tabCount); })), null); }
public void ObjRefToString(IObjRef objRef, StringBuilder sb) { sb.Append("ObjRef "); sbyte idIndex = objRef.IdNameIndex; if (idIndex == ObjRef.PRIMARY_KEY_INDEX) { sb.Append("PK="); } else { sb.Append("AK").Append(idIndex).Append('='); } StringBuilderUtil.AppendPrintable(sb, objRef.Id); sb.Append(" version=").Append(objRef.Version).Append(" type=").Append(objRef.RealType.FullName); }
public override void ToString(StringBuilder sb) { if (IsCreate()) { sb.Append(typeof(CreateContainer).Name).Append(": "); } else if (IsUpdate()) { sb.Append(typeof(UpdateContainer).Name).Append(": "); } else { base.ToString(sb); return; } StringBuilderUtil.AppendPrintable(sb, Reference); }
public String GenerateBeanName(Type beanType) { return(StringBuilderUtil.Concat(delegate(StringBuilder sb) { int anonymousCounter = ++this.anonymousCounter; if (typeInfoProvider != null) { sb.Append(typeInfoProvider.GetTypeInfo(beanType).SimpleName); } else { sb.Append(beanType.Name); } sb.Append('#').Append(anonymousCounter); })); }
public void ToStringSbCompositeId(ITypeInfoItem[] members, Object compositeId, StringBuilder sb) { // order does matter here for (int a = 0, size = members.Length; a < size; a++) { Object value = members[a].GetValue(compositeId); if (a > 0) { sb.Append('#'); } if (value != null) { StringBuilderUtil.AppendPrintable(sb, value); } else { sb.Append("<null>"); } } }
public static void ToStringSbCompositeId(Object compositeId, StringBuilder sb) { // order does matter here FieldInfo[] fields = compositeId.GetType().GetFields(); for (int a = 0, size = fields.Length; a < size; a++) { FieldInfo field = fields[a]; Object value = field.GetValue(compositeId); if (a > 0) { sb.Append('#'); } if (value != null) { StringBuilderUtil.AppendPrintable(sb, value); } else { sb.Append("<null>"); } } }
protected MethodInfo[] GetAddRemoveMethodsIntern(Type extendableInterface, String propertyName, Type[] argumentTypes) { int expectedParamCount = argumentTypes.Length + 1; KeyItem keyItem = KeyItemProp; keyItem.ExtendableInterface = extendableInterface; keyItem.PropertyName = propertyName; keyItem.ArgumentCount = expectedParamCount; MethodInfo[] addRemoveMethods = Get(keyItem); if (addRemoveMethods != null) { return(addRemoveMethods); } keyItem = new KeyItem(extendableInterface, propertyName, expectedParamCount); Object writeLock = GetWriteLock(); lock (writeLock) { addRemoveMethods = Get(keyItem); if (addRemoveMethods != null) { // Concurrent thread might have been faster return(addRemoveMethods); } String registerMethodName1 = null, registerMethodName2 = null; String unregisterMethodName1 = null, unregisterMethodName2 = null; if (propertyName != null) { registerMethodName1 = StringBuilderUtil.Concat("register", propertyName).ToLowerInvariant(); registerMethodName2 = StringBuilderUtil.Concat("add_", propertyName).ToLowerInvariant(); unregisterMethodName1 = StringBuilderUtil.Concat("remove_", propertyName).ToLowerInvariant(); unregisterMethodName2 = StringBuilderUtil.Concat("unregister", propertyName).ToLowerInvariant(); } MethodInfo[] methods = extendableInterface.GetMethods(); MethodInfo addMethod = null, removeMethod = null; foreach (MethodInfo method in methods) { ParameterInfo[] paramInfos = method.GetParameters(); if (paramInfos.Length != expectedParamCount) { continue; } String methodName = method.Name.ToLower(); if (propertyName != null && !methodName.Equals(registerMethodName1) && !methodName.Equals(registerMethodName2) && !methodName.Equals(unregisterMethodName1) && !methodName.Equals(unregisterMethodName2)) { continue; } if (methodName.StartsWith("register") || methodName.StartsWith("add")) { bool match = true; for (int a = paramInfos.Length; a-- > 1;) { ParameterInfo paramInfo = paramInfos[a]; Type argumentType = argumentTypes[a - 1]; if (argumentType != null && !UnboxType(paramInfo.ParameterType).IsAssignableFrom(UnboxType(argumentType))) { match = false; break; } } if (match) { addMethod = method; } } else if (methodName.StartsWith("unregister") || methodName.StartsWith("remove")) { bool match = true; for (int a = paramInfos.Length; a-- > 1;) { ParameterInfo paramInfo = paramInfos[a]; Type argumentType = argumentTypes[a - 1]; if (argumentType != null && !UnboxType(paramInfo.ParameterType).IsAssignableFrom(UnboxType(argumentType))) { match = false; break; } } if (match) { removeMethod = method; } } } if (addMethod == null || removeMethod == null) { throw new ExtendableException("No extendable methods pair like 'add/remove' or 'register/unregister' found on interface " + extendableInterface.FullName + " to add extension signature with exactly " + expectedParamCount + " argument(s)"); } addRemoveMethods = new MethodInfo[] { addMethod, removeMethod }; Put(keyItem, addRemoveMethods); return(addRemoveMethods); } }
public virtual void ToString(StringBuilder sb) { sb.Append(GetType().Name).Append(": "); StringBuilderUtil.AppendPrintable(sb, Reference); }
void Start() { Int2StringFormatTest(-0, 2); Int2StringFormatTest(-100, 3); Int2StringFormatTest(-123, 4); Int2StringFormatTest(-123, 5); Int2StringFormatTest(123, 5); Int2StringFormatTest(123, 2); string s0 = "aabbccddeeff"; string s1 = "aa,bb,ccddee"; { Profiler.BeginSample("char[] 1"); char[] txt = new char[1] { 'a' }; Profiler.EndSample(); // 28byte Profiler.BeginSample("string 1"); string s = new string(txt); Profiler.EndSample(); // 28byte Profiler.BeginSample("string 1 copy"); string ss = string.Copy(s); Profiler.EndSample(); } { char[] txt = new char[10]; for (int i = 0; i < txt.Length; i++) { txt[i] = '0'; } // 46byte Profiler.BeginSample("string 10"); string s = new string(txt); Profiler.EndSample(); } // 90byte Profiler.BeginSample("split 1"); string[] array = s0.Split(','); Profiler.EndSample(); // 48byte { Profiler.BeginSample("no split"); if (s0.IndexOf(',') >= 0) { } else { array = new string[] { s0 }; } Profiler.EndSample(); } // 204byte { Profiler.BeginSample("split 3"); array = s1.Split(','); Profiler.EndSample(); } string[] num = { "0", "1", "2", "3", "4", "5" }; { Profiler.BeginSample("concat3"); string s = num[0] + num[1] + num[2]; Profiler.EndSample(); } // GC.Alloc x1 34B { Profiler.BeginSample("concat +"); string s = num[0] + num[1] + num[2] + num[3]; Profiler.EndSample(); } // GC.Alloc x3 96B { Profiler.BeginSample("concat +="); string s = num[0]; s += num[1]; s += num[2]; s += num[3]; Profiler.EndSample(); } // 180B { Profiler.BeginSample("concat + 5"); // 5個以上の場合、配列が生成される string s = num[0] + num[1] + num[2] + num[3] + num[4]; Profiler.EndSample(); } // 180B { Profiler.BeginSample("concat new array"); string s = string.Concat(new string[] { num[0], num[1], num[2], num[3], num[4] }); Profiler.EndSample(); } // 118B { Profiler.BeginSample("concat array"); // Concatは配列がコピーされる(.NET Framework) string s = string.Concat(num); Profiler.EndSample(); } // 38B { Profiler.BeginSample("join empty"); string s = string.Join("", num); Profiler.EndSample(); } // 150byte { Profiler.BeginSample("StringBuilder"); var sb = new System.Text.StringBuilder(); for (int i = 0; i < num.Length; i++) { sb.Append(num[i]); } string s = sb.ToString(); Profiler.EndSample(); } // 32byte { Profiler.BeginSample("$3"); // string.Concatが呼ばれる string s = $"{num[0]}{num[1]}{num[2]}"; Profiler.EndSample(); } // 32byte { Profiler.BeginSample("Format3"); string s = string.Format("{0}{1}{2}", num[0], num[1], num[2]); Profiler.EndSample(); } // 50byte { Profiler.BeginSample("replace string"); string r = s1.Replace(",", "."); Profiler.EndSample(); } // 50byte { Profiler.BeginSample("replace char"); string r = s1.Replace(',', '.'); Profiler.EndSample(); } // 0byte { Profiler.BeginSample("no replace"); string r = s1.Replace('@', '.'); Profiler.EndSample(); } // 32byte { Profiler.BeginSample("int -> string (ToString)"); int i0 = 100; string s = i0.ToString(); Profiler.EndSample(); } // 506byte { Profiler.BeginSample("int -> string (ToString) 2"); int i0 = 100; string s = (i0).ToString("0000"); Profiler.EndSample(); } // 34byte { Profiler.BeginSample("int -> string (ToString) 3"); int i0 = 100; string s = (i0).ToString("D4"); Profiler.EndSample(); } // 84byte { Profiler.BeginSample("int -> string (Format)"); int i0 = 100; string s = string.Format("{0}", i0); Profiler.EndSample(); } // 0.7KB { Profiler.BeginSample("int -> string (Format) 2"); int i0 = 100; string s = string.Format("{0:0000}", i0); Profiler.EndSample(); Debug.Log(s); } // 74byte { Profiler.BeginSample("int -> string (Custom)"); int i0 = 100; string s = IntToStringUtil.Padding0(i0, 4); Profiler.EndSample(); Debug.Log(s); } // 34byte { Profiler.BeginSample("int -> string (Custom Unsafe)"); int i0 = 100; string s = IntToStringUtil.UnsafePadding0(i0, 4); Profiler.EndSample(); Debug.Log(s); } // 30byte { Profiler.BeginSample("int -> string Hex (ToString)"); int i0 = 100; string s = i0.ToString("X"); Profiler.EndSample(); Debug.Log(s); } // 220byte { Profiler.BeginSample("int -> string Hex (Format)"); int i0 = 100; string s = string.Format("{0:X}", i0); Profiler.EndSample(); Debug.Log(s); } // 84byte { Profiler.BeginSample("int -> string ($)"); int i0 = 100; string s = $"{i0}"; Profiler.EndSample(); } // 28byte { Profiler.BeginSample("last char (SubString)"); string s = s0.Substring(s0.Length - 1); Profiler.EndSample(); } // 28byte { Profiler.BeginSample("last char (ToString)"); string s = s0[s0.Length - 1].ToString(); Profiler.EndSample(); } // 48byte { Profiler.BeginSample("join"); string s = string.Join(",", num); Profiler.EndSample(); } // 88byte { List <string> list = new List <string>(num); Profiler.BeginSample("join List"); string s = string.Join(",", list); Profiler.EndSample(); } // 162byte { Profiler.BeginSample("StringBuilder join"); var sb = new System.Text.StringBuilder(); for (int i = 0; i < num.Length; i++) { sb.Append(num[0]); sb.Append(","); } string s = sb.ToString(); Profiler.EndSample(); } { Profiler.BeginSample("concat null"); string s = s0 + null; Profiler.EndSample(); } { Profiler.BeginSample("concat empty"); string s = s0 + ""; Profiler.EndSample(); } // 108byte { Profiler.BeginSample("concat int"); int i = 123; string s = s0 + i; Profiler.EndSample(); } // 88byte { Profiler.BeginSample("concat int.ToString"); int i = 123; string s = s0 + i.ToString(); Profiler.EndSample(); } // 80byte { Profiler.BeginSample("concat char"); char c = '0'; string s = s0 + c; Profiler.EndSample(); Debug.Log(s); } // 80byte { Profiler.BeginSample("concat char.ToString"); char c = '0'; string s = s0 + c.ToString(); Profiler.EndSample(); Debug.Log(s); } // 0byte { Profiler.BeginSample("String.ToString"); string s = s0.ToString(); Profiler.EndSample(); } // 0byte { Profiler.BeginSample("String.ToString"); object o = s0; string s = o.ToString(); Profiler.EndSample(); } { Profiler.BeginSample("string =="); string a = "hoge"; string b = "fuga"; for (int i = 0; i < 1000; i++) { bool ret = a == b; } Profiler.EndSample(); } { Profiler.BeginSample("string.CompareTo"); string a = "hoge"; string b = "fuga"; for (int i = 0; i < 1000; i++) { bool ret = a.CompareTo(b) == 0; } Profiler.EndSample(); } { Profiler.BeginSample("string.Compare"); string a = "hoge"; string b = "fuga"; for (int i = 0; i < 1000; i++) { bool ret = string.Compare(a, b, System.StringComparison.Ordinal) == 0; } Profiler.EndSample(); } { Profiler.BeginSample("IndexOf default"); for (int i = 0; i < 1000; i++) { bool ret = s0.IndexOf("bbccddee") >= 0; } Profiler.EndSample(); } { Profiler.BeginSample("IndexOf Ordinal"); for (int i = 0; i < 1000; i++) { // Containsと同じ bool ret = s0.IndexOf("bbccddee", System.StringComparison.Ordinal) >= 0; } Profiler.EndSample(); } // 0は同じリテラルを返す // 0byte { Profiler.BeginSample("int.ToString 0"); int n = 0; string s = n.ToString(); Profiler.EndSample(); int m = 0; string ss = m.ToString(); // true Debug.Log(object.ReferenceEquals(ss, s)); } // 1は文字列を生成して返す(.NET Coreでは1桁の数値はリテラルを返す) // 28byte { Profiler.BeginSample("int.ToString 1"); int n = 1; string s = n.ToString(); Profiler.EndSample(); int m = 1; string ss = m.ToString(); // false Debug.Log(object.ReferenceEquals(ss, s)); } int[] numbers = { 0, 1, 12, 123, -3, -32, -321 }; // .NET Frameworkの実装ではint.ToStringされる // 186byte { var sb = new System.Text.StringBuilder(100); Profiler.BeginSample("StringBuilder number 1"); for (int i = 0; i < numbers.Length; i++) { sb.Append(numbers[i]); } Profiler.EndSample(); string s = sb.ToString(); Debug.Log(s); } // 0byte { var sb = new System.Text.StringBuilder(100); Profiler.BeginSample("StringBuilder number 2"); for (int i = 0; i < numbers.Length; i++) { int n = numbers[i]; StringBuilderUtil.AppendInt(sb, n); } Profiler.EndSample(); string s = sb.ToString(); Debug.Log(s); } // boolは文字列リテラルが使われる // 0byte { var sb = new System.Text.StringBuilder(100); Profiler.BeginSample("StringBuilder bool"); bool t = true; bool f = false; for (int i = 0; i < 10; i++) { sb.Append(i % 2 == 0 ? t : f); } Profiler.EndSample(); string s = sb.ToString(); Debug.Log(s); } // 350byte { var sb = new System.Text.StringBuilder(100); Profiler.BeginSample("StringBuilder bool lower"); bool t = true; bool f = false; for (int i = 0; i < 10; i++) { bool b = i % 2 == 0 ? t : f; sb.Append(b.ToString().ToLower()); } Profiler.EndSample(); string s = sb.ToString(); Debug.Log(s); } // 0byte { var sb = new System.Text.StringBuilder(100); Profiler.BeginSample("StringBuilder bool lower literal"); bool t = true; bool f = false; for (int i = 0; i < 10; i++) { string b = i % 2 == 0 ? "true" : "false"; sb.Append(b); } Profiler.EndSample(); string s = sb.ToString(); Debug.Log(s); } // 0byte { var sb = new System.Text.StringBuilder(); Profiler.BeginSample("StringBuilder AppendFormat"); string msg = "hoge"; sb.AppendFormat("huga_{0}", msg); Profiler.EndSample(); string s = sb.ToString(); Debug.Log(s); } // 44byte { var sb = new System.Text.StringBuilder(); Profiler.BeginSample("StringBuilder Append $"); string msg = "hoge"; sb.Append($"huga_{msg}"); Profiler.EndSample(); string s = sb.ToString(); Debug.Log(s); } }
public String GetPropertyNameFor(FieldInfo field) { return(StringBuilderUtil.UpperCaseFirst(field.Name)); }
public void ToString(StringBuilder sb) { StringBuilderUtil.AppendPrintable(sb, Key); }
public void Dispose() { if (disposed || disposing) { return; } ILogger log; IServiceContext[] childrenCopy = null; writeLock.Lock(); try { if (disposed || disposing) { return; } log = GetService <ILoggerCache>().GetCachedLogger(this, typeof(ServiceContext)); if (log.DebugEnabled) { // Safe the toString-method for debugging purpose. Because this is not possible anymore if the context // has been disposed and all bean-references have been cleared toStringBackup = StringBuilderUtil.Concat(delegate(StringBuilder sb) { PrintContent(sb); }); } else { toStringBackup = "n/a"; } disposing = true; if (children != null && children.Count > 0) { childrenCopy = new IServiceContext[children.Count]; children.CopyTo(childrenCopy, 0); children.Clear(); } } finally { writeLock.Unlock(); } if (childrenCopy != null) { foreach (IServiceContext childContext in childrenCopy) { try { childContext.Dispose(); } catch (Exception e) { if (log.ErrorEnabled) { log.Error(e); } } } } writeLock.Lock(); try { if (parent != null) { parent.ChildContextDisposed(this); parent = null; } if (this.linkContainers != null) { IList <ILinkContainer> linkContainers = this.linkContainers; this.linkContainers = null; for (int a = linkContainers.Count; a-- > 0;) { ILinkContainer listenerContainer = linkContainers[a]; try { listenerContainer.Unlink(); } catch (System.Exception e) { if (failOnError) { throw; } if (log.ErrorEnabled) { log.Error(e); } } } } if (this.disposableObjects != null) { IList <Object> disposableObjects = this.disposableObjects; this.disposableObjects = null; for (int a = disposableObjects.Count; a-- > 0;) { Object disposableObject = disposableObjects[a]; if (disposableObject is WeakReference) { disposableObject = ((WeakReference)disposableObject).Target; } if (disposableObject is IDisposableBean) { try { ((IDisposableBean)disposableObject).Destroy(); } catch (System.Exception e) { if (failOnError) { throw; } if (log.ErrorEnabled) { log.Error(e); } } } else if (disposableObject is IDisposable) { try { ((IDisposable)disposableObject).Dispose(); } catch (System.Exception e) { if (failOnError) { throw; } if (log.ErrorEnabled) { log.Error(e); } } } else if (disposableObject is IBackgroundWorkerParamDelegate <IServiceContext> ) { try { ((IBackgroundWorkerParamDelegate <IServiceContext>)disposableObject).Invoke(this); } catch (System.Exception e) { if (failOnError) { throw; } if (log.ErrorEnabled) { log.Error(e); } } } } } if (nameToServiceDict != null) { nameToServiceDict.Clear(); } typeToServiceDict.Clear(); if (postProcessors != null) { postProcessors.Clear(); } if (preProcessors != null) { preProcessors.Clear(); } beanContextFactory.Dispose(); } finally { writeLock.Unlock(); beanContextFactory = null; linkContainers = null; nameToServiceDict = null; postProcessors = null; preProcessors = null; parent = null; disposed = true; running = false; } }
public void ToString(StringBuilder sb) { sb.Append("ObjRel: memberName=").Append(MemberName).Append(", ref="); StringBuilderUtil.AppendPrintable(sb, objRefs); }
public void ToString(IEntityEquals left, StringBuilder sb) { sb.Append(left.Get__BaseType().FullName).Append('-'); StringBuilderUtil.AppendPrintable(sb, left.Get__Id()); }