From e31b424064de082f61450ff29b0bdc892033495b Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sat, 15 Mar 2008 04:28:47 +0000 Subject: [PATCH] Changed parsing of Time tags, which results in ~30% faster ASS loading. Originally committed to SVN as r2061. --- aegilib/include/aegilib/gorgontime.h | 2 +- aegilib/include/aegilib/utils.h | 1 + aegilib/src/time.cpp | 34 ++++++++++++++++------------ aegilib/src/utils.cpp | 15 ++++++++++++ 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/aegilib/include/aegilib/gorgontime.h b/aegilib/include/aegilib/gorgontime.h index 4c4a7c1a4..c1260bed1 100644 --- a/aegilib/include/aegilib/gorgontime.h +++ b/aegilib/include/aegilib/gorgontime.h @@ -51,7 +51,7 @@ namespace Gorgonsub { int GetMS() const { return ms; } String GetString(int ms_precision,int h_precision) const; - void Parse(String data); + void Parse(const String &data); }; }; diff --git a/aegilib/include/aegilib/utils.h b/aegilib/include/aegilib/utils.h index 124a68907..3495c1c49 100644 --- a/aegilib/include/aegilib/utils.h +++ b/aegilib/include/aegilib/utils.h @@ -71,6 +71,7 @@ namespace Gorgonsub { // Convert a string to an integer int StringToInt(const String &str); + int SubStringToInteger(const String &str,size_t start,size_t end); // Number to string functions String PrettyFloat(String src); diff --git a/aegilib/src/time.cpp b/aegilib/src/time.cpp index 1dce5096e..e30de2578 100644 --- a/aegilib/src/time.cpp +++ b/aegilib/src/time.cpp @@ -109,30 +109,34 @@ String Time::GetString(int ms_precision,int h_precision) const /////////////////// // Parses a string -void Time::Parse(String data) +void Time::Parse(const String &data) { // Break into an array of values - std::vector values; - values.reserve(4); + std::vector values(4); size_t last = 0; - data += _T(":"); size_t len = data.Length(); + size_t curIndex = 0; + wxChar cur = 0; for (size_t i=0;i=0;) { - ms += (int)(values[i] * mult); - mult *= 60.0; + size_t mult[] = { 0, 1, 1000, 60000, 3600000 }; + size_t accum = 0; + for (int i=(int)curIndex;--i>=0;) { + accum += values[i] * mult[curIndex-i]; } + ms = (int)accum; } diff --git a/aegilib/src/utils.cpp b/aegilib/src/utils.cpp index eb4e31d60..1e4e280a5 100644 --- a/aegilib/src/utils.cpp +++ b/aegilib/src/utils.cpp @@ -42,6 +42,7 @@ using namespace Gorgonsub; // Convert a string to an integer int Gorgonsub::StringToInt(const String &str) { + // TODO: optimize if (!str.IsNumber()) return 0; long temp; str.ToLong(&temp); @@ -49,6 +50,20 @@ int Gorgonsub::StringToInt(const String &str) } +////////////////////////////////////// +// Converts a substring to an integer +int Gorgonsub::SubStringToInteger(const String &str,size_t start,size_t end) +{ + int value = 0; + int chr; + for (size_t i=start;i= 0 && chr <= 9) value = 10*value+chr; + } + return value; +} + + //////////////// // Pretty float String Gorgonsub::PrettyFloat(String src) {