From fb7fb65d6d57edbf52d7ab7759a36a6034aff0a9 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 25 Dec 2009 22:24:04 +0000 Subject: WinGui: - Hopefully a significant performance improvement in the Parser ReadLine() Function. This should help when the CLI is throwing out huge amounts of read errors / logging data. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3044 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Parsing/Parser.cs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/win/C#/Parsing/Parser.cs b/win/C#/Parsing/Parser.cs index b3bca0187..ed199ed2a 100644 --- a/win/C#/Parsing/Parser.cs +++ b/win/C#/Parsing/Parser.cs @@ -5,6 +5,7 @@ It may be used under the terms of the GNU General Public License. */ using System.IO; +using System.Text; using System.Text.RegularExpressions; using System; using System.Globalization; @@ -38,21 +39,21 @@ namespace Handbrake.Parsing /// The estimated time remaining for this task to complete public delegate void EncodeProgressEventHandler(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining); - + /// /// A simple wrapper around a StreamReader to keep track of the entire output from a cli process /// internal class Parser : StreamReader { - private string m_buffer; + private StringBuilder _buffer = new StringBuilder(""); /// /// The output from the CLI process /// - public string Buffer + public String Buffer { get { - return m_buffer; + return _buffer.ToString(); } } @@ -82,22 +83,27 @@ namespace Handbrake.Parsing /// Default constructor for this object /// /// The stream to parse from - public Parser(Stream baseStream) : base(baseStream) + public Parser(Stream baseStream) + : base(baseStream) { - m_buffer = string.Empty; } public override string ReadLine() { string tmp = base.ReadLine(); - m_buffer += tmp + Environment.NewLine; - Match m = Regex.Match(tmp, "^Scanning title ([0-9]*) of ([0-9]*)"); + _buffer.AppendLine(tmp); + + Match m = null; + if (tmp.Contains("Scanning title")) + m = Regex.Match(tmp, "^Scanning title ([0-9]*) of ([0-9]*)"); + if (OnReadLine != null) OnReadLine(this, tmp); - if (m.Success && OnScanProgress != null) - OnScanProgress(this, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value)); + if (m != null) + if (m.Success && OnScanProgress != null) + OnScanProgress(this, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value)); return tmp; } @@ -106,7 +112,8 @@ namespace Handbrake.Parsing { string tmp = base.ReadToEnd(); - m_buffer += tmp + Environment.NewLine; + _buffer.AppendLine(tmp); + if (OnReadToEnd != null) OnReadToEnd(this, tmp); -- cgit v1.2.3