internal static object Multiply(IEnumerator enumerator, int times) { NonEnumerableObjectEnumerator enumerator2 = enumerator as NonEnumerableObjectEnumerator; if (enumerator2 != null) { return(ParserOps.ImplicitOp(enumerator2.GetNonEnumerableObject(), times, "op_Multiply", null, "*")); } ArrayList list = new ArrayList(); while (MoveNext(null, enumerator)) { list.Add(Current(enumerator)); } if (list.Count == 0) { return(new object[0]); } return(ArrayOps.Multiply <object>(list.ToArray(), times)); }
internal static string Multiply(string s, int times) { if (times < 0) { throw new ArgumentOutOfRangeException("times"); } if ((times == 0) || (s.Length == 0)) { return(string.Empty); } ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS(); if (((executionContextFromTLS != null) && (executionContextFromTLS.LanguageMode == PSLanguageMode.RestrictedLanguage)) && ((s.Length * times) > 0x400)) { throw InterpreterError.NewInterpreterException(times, typeof(RuntimeException), null, "StringMultiplyToolongInDataSection", ParserStrings.StringMultiplyToolongInDataSection, new object[] { 0x400 }); } if (s.Length == 1) { return(new string(s[0], times)); } return(new string(ArrayOps.Multiply <char>(s.ToCharArray(), (int)times))); }
internal static string Multiply(string s, int times) { Diagnostics.Assert(s != null, "caller to verify argument is not null"); if (times < 0) { // TODO: this should be a runtime error. throw new ArgumentOutOfRangeException("times"); } if (times == 0 || s.Length == 0) { return(String.Empty); } var context = LocalPipeline.GetExecutionContextFromTLS(); if (context != null && context.LanguageMode == PSLanguageMode.RestrictedLanguage && (s.Length * times) > 1024) { throw InterpreterError.NewInterpreterException(times, typeof(RuntimeException), null, "StringMultiplyToolongInDataSection", ParserStrings.StringMultiplyToolongInDataSection, 1024); } if (s.Length == 1) { // A string of length 1 has special support in the BCL, so just use it. return(new string(s[0], times)); } // Convert the string to a char array, use the array multiplication code, // then construct a new string from the resulting char array. This uses // extra memory compared to the naive algorithm, but is faster (measured // against a V2 CLR, should be measured against V4 as the StringBuilder // implementation changed.) return(new string(ArrayOps.Multiply(s.ToCharArray(), (uint)times))); }