mirror of https://github.com/odrling/Aegisub
Changed parsing of Time tags, which results in ~30% faster ASS loading.
Originally committed to SVN as r2061.
This commit is contained in:
parent
d6d3f8aecb
commit
e31b424064
|
@ -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);
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<double> values;
|
||||
values.reserve(4);
|
||||
std::vector<size_t> 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<len;i++) {
|
||||
if (data[i] == ':' || data[i] == ';') {
|
||||
wxString temp = data.Mid(last,i-last);
|
||||
cur = data[i];
|
||||
if (cur == ':' || cur == '.' || cur == ',' || cur == ';') {
|
||||
values.at(curIndex++) = SubStringToInteger(data,last,i);
|
||||
last = i+1;
|
||||
double tempd;
|
||||
temp.ToDouble(&tempd);
|
||||
values.push_back(tempd);
|
||||
}
|
||||
if (i == len-1) {
|
||||
int value = SubStringToInteger(data,last,len);
|
||||
size_t digits = len - last;
|
||||
if (digits == 2) value *= 10;
|
||||
if (digits == 1) value *= 100;
|
||||
values.at(curIndex++) = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Turn into milliseconds
|
||||
ms = 0;
|
||||
double mult = 1000.0;
|
||||
int len2 = (int) values.size();
|
||||
for (int i=len2;--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;
|
||||
}
|
||||
|
|
|
@ -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<end;i++) {
|
||||
chr = (int)str[i]-(int)'0';
|
||||
if (chr >= 0 && chr <= 9) value = 10*value+chr;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
////////////////
|
||||
// Pretty float
|
||||
String Gorgonsub::PrettyFloat(String src) {
|
||||
|
|
Loading…
Reference in New Issue