Replace some uses of "" with wxString()

Despite special-casing zero-length input, wxString("") takes over four
times as long as wxString() - and on a 10k line script, this change cuts
AssFile's copy constructor's runtime in half.

Originally committed to SVN as r6401.
This commit is contained in:
Thomas Goyne 2012-01-31 00:44:43 +00:00
parent 3b0d2ae8e6
commit c2d3c910c7
14 changed files with 22 additions and 30 deletions

View file

@ -49,21 +49,18 @@
#include "utils.h" #include "utils.h"
AssDialogue::AssDialogue() AssDialogue::AssDialogue()
: Comment(false) : AssEntry(wxString(), "[Events]")
, Comment(false)
, Layer(0) , Layer(0)
, Start(0) , Start(0)
, End(5000) , End(5000)
, Style("Default") , Style("Default")
, Actor("")
, Effect("")
, Text("")
{ {
group = "[Events]";
for (int i=0;i<4;i++) Margin[i] = 0; for (int i=0;i<4;i++) Margin[i] = 0;
} }
AssDialogue::AssDialogue(AssDialogue const& that) AssDialogue::AssDialogue(AssDialogue const& that)
: AssEntry() : AssEntry(wxString(), "[Events]")
, Comment(that.Comment) , Comment(that.Comment)
, Layer(that.Layer) , Layer(that.Layer)
, Start(that.Start) , Start(that.Start)
@ -73,7 +70,6 @@ AssDialogue::AssDialogue(AssDialogue const& that)
, Effect(that.Effect) , Effect(that.Effect)
, Text(that.Text) , Text(that.Text)
{ {
group = that.group;
for (int i=0;i<4;i++) Margin[i] = that.Margin[i]; for (int i=0;i<4;i++) Margin[i] = that.Margin[i];
} }
@ -81,16 +77,13 @@ AssDialogue::AssDialogue(AssDialogue const& that)
/// @param _data /// @param _data
/// @param version /// @param version
AssDialogue::AssDialogue(wxString _data,int version) AssDialogue::AssDialogue(wxString _data,int version)
: Comment(false) : AssEntry(wxString(), "[Events]")
, Comment(false)
, Layer(0) , Layer(0)
, Start(0) , Start(0)
, End(5000) , End(5000)
, Style("Default") , Style("Default")
, Actor("")
, Effect("")
, Text("")
{ {
group = "[Events]";
bool valid = false; bool valid = false;
// Try parsing in different ways // Try parsing in different ways
int count = 0; int count = 0;
@ -363,7 +356,7 @@ void AssDialogue::SetMarginString(const wxString origvalue,int which) {
// Make it numeric // Make it numeric
wxString strvalue = origvalue; wxString strvalue = origvalue;
if (!strvalue.IsNumber()) { if (!strvalue.IsNumber()) {
strvalue = ""; strvalue.clear();
for (size_t i=0;i<origvalue.Length();i++) { for (size_t i=0;i<origvalue.Length();i++) {
if (origvalue.Mid(i,1).IsNumber()) { if (origvalue.Mid(i,1).IsNumber()) {
strvalue += origvalue.Mid(i,1); strvalue += origvalue.Mid(i,1);

View file

@ -96,7 +96,7 @@ public:
class AssDialogueBlockPlain : public AssDialogueBlock { class AssDialogueBlockPlain : public AssDialogueBlock {
public: public:
ASS_BlockType GetType() { return BLOCK_PLAIN; } ASS_BlockType GetType() { return BLOCK_PLAIN; }
AssDialogueBlockPlain(wxString const& text = "") : AssDialogueBlock(text) { } AssDialogueBlockPlain(wxString const& text = wxString()) : AssDialogueBlock(text) { }
}; };
/// @class AssDialogueBlockDrawing /// @class AssDialogueBlockDrawing
@ -109,7 +109,7 @@ public:
int Scale; int Scale;
ASS_BlockType GetType() { return BLOCK_DRAWING; } ASS_BlockType GetType() { return BLOCK_DRAWING; }
AssDialogueBlockDrawing(wxString const& text = "") : AssDialogueBlock(text) { } AssDialogueBlockDrawing(wxString const& text = wxString()) : AssDialogueBlock(text) { }
void TransformCoords(int trans_x,int trans_y,double mult_x,double mult_y); void TransformCoords(int trans_x,int trans_y,double mult_x,double mult_y);
}; };
@ -119,7 +119,7 @@ public:
/// DOCME /// DOCME
class AssDialogueBlockOverride : public AssDialogueBlock { class AssDialogueBlockOverride : public AssDialogueBlock {
public: public:
AssDialogueBlockOverride(wxString const& text = "") : AssDialogueBlock(text) { } AssDialogueBlockOverride(wxString const& text = wxString()) : AssDialogueBlock(text) { }
~AssDialogueBlockOverride(); ~AssDialogueBlockOverride();
/// DOCME /// DOCME

View file

@ -82,7 +82,7 @@ public:
/// Group it belongs to, e.g. "[Events]" /// Group it belongs to, e.g. "[Events]"
wxString group; wxString group;
AssEntry(wxString const& data = "", wxString const& group = "") : data(data), group(group) { } AssEntry(wxString const& data = wxString(), wxString const& group = wxString()) : data(data), group(group) { }
virtual ~AssEntry() { } virtual ~AssEntry() { }
/// Create a copy of this entry /// Create a copy of this entry

View file

@ -441,7 +441,6 @@ namespace Automation4 {
} else if (first_char == '$') { } else if (first_char == '$') {
basepath = autobasefn; basepath = autobasefn;
} else if (first_char == '/') { } else if (first_char == '/') {
basepath = "";
} else { } else {
wxLogWarning("Automation Script referenced with unknown location specifier character.\nLocation specifier found: %c\nFilename specified: %s", wxLogWarning("Automation Script referenced with unknown location specifier character.\nLocation specifier found: %c\nFilename specified: %s",
first_char, trimmed); first_char, trimmed);

View file

@ -123,7 +123,7 @@ namespace Automation4 {
/// @param set_undo If there's any uncommitted changes to the file, /// @param set_undo If there's any uncommitted changes to the file,
/// they will be automatically committed with this /// they will be automatically committed with this
/// description /// description
void ProcessingComplete(wxString const& undo_description = ""); void ProcessingComplete(wxString const& undo_description = wxString());
/// End processing without applying any changes made /// End processing without applying any changes made
void Cancel(); void Cancel();

View file

@ -302,7 +302,7 @@ namespace Automation4 {
wxString section = get_string_field(L, "section", "common"); wxString section = get_string_field(L, "section", "common");
if (lclass == "clear") if (lclass == "clear")
result = new AssEntry(""); result = new AssEntry;
else if (lclass == "comment") else if (lclass == "comment")
result = new AssEntry(";" + get_string_field(L, "text", "comment")); result = new AssEntry(";" + get_string_field(L, "text", "comment"));
else if (lclass == "head") else if (lclass == "head")

View file

@ -136,7 +136,7 @@ public:
ColorPickerRecent(wxWindow *parent, int cols, int rows, int cellsize); ColorPickerRecent(wxWindow *parent, int cols, int rows, int cellsize);
/// Load the colors to show from a string /// Load the colors to show from a string
void LoadFromString(const wxString &recent_string = ""); void LoadFromString(const wxString &recent_string = wxString());
/// Save the colors currently shown to a string /// Save the colors currently shown to a string
wxString StoreToString(); wxString StoreToString();
/// Add a color to the beginning of the recent list /// Add a color to the beginning of the recent list

View file

@ -617,7 +617,7 @@ void DialogStyleManager::OnCurrentCopy (wxCommandEvent &) {
/// @param list /// @param list
/// @param v /// @param v
void DialogStyleManager::CopyToClipboard (wxListBox *list, std::vector<AssStyle*> v) { void DialogStyleManager::CopyToClipboard (wxListBox *list, std::vector<AssStyle*> v) {
wxString data = ""; wxString data;
AssStyle *s; AssStyle *s;
wxArrayInt selections; wxArrayInt selections;
list->GetSelections(selections); list->GetSelections(selections);
@ -637,7 +637,7 @@ void DialogStyleManager::CopyToClipboard (wxListBox *list, std::vector<AssStyle*
/// @brief Paste from clipboard /// @brief Paste from clipboard
void DialogStyleManager::PasteToCurrent() { void DialogStyleManager::PasteToCurrent() {
wxString data = ""; wxString data;
if (wxTheClipboard->Open()) { if (wxTheClipboard->Open()) {
if (wxTheClipboard->IsSupported(wxDF_TEXT)) { if (wxTheClipboard->IsSupported(wxDF_TEXT)) {
@ -669,7 +669,7 @@ void DialogStyleManager::PasteToCurrent() {
/// @brief DOCME /// @brief DOCME
void DialogStyleManager::PasteToStorage() { void DialogStyleManager::PasteToStorage() {
wxString data = ""; wxString data;
if (wxTheClipboard->Open()) { if (wxTheClipboard->Open()) {
if (wxTheClipboard->IsSupported(wxDF_TEXT)) { if (wxTheClipboard->IsSupported(wxDF_TEXT)) {

View file

@ -57,5 +57,5 @@ public:
void SetUnicodeStyling(int start,int length,int style); void SetUnicodeStyling(int start,int length,int style);
void SetSelectionU(int start,int end); void SetSelectionU(int start,int end);
ScintillaTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = "", const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0); ScintillaTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = wxString(), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
}; };

View file

@ -100,7 +100,7 @@ std::pair<int, int> get_selection(SubsTextEditCtrl *TextEdit) {
/// @param tag Tag to get the value of /// @param tag Tag to get the value of
/// @param alt Alternate name of the tag, if any /// @param alt Alternate name of the tag, if any
template<class T> template<class T>
static T get_value(AssDialogue const& line, int blockn, T initial, wxString tag, wxString alt = "") { static T get_value(AssDialogue const& line, int blockn, T initial, wxString tag, wxString alt = wxString()) {
for (int i = blockn; i >= 0; i--) { for (int i = blockn; i >= 0; i--) {
AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(line.Blocks[i]); AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(line.Blocks[i]);
if (!ovr) continue; if (!ovr) continue;

View file

@ -181,7 +181,7 @@ void SubtitlesGrid::InsertLine(AssDialogue *line,int n,bool after,bool update) {
void SubtitlesGrid::CopyLines(wxArrayInt target) { void SubtitlesGrid::CopyLines(wxArrayInt target) {
// Prepare text // Prepare text
wxString data = ""; wxString data;
AssDialogue *cur; AssDialogue *cur;
int nrows = target.Count(); int nrows = target.Count();
bool first = true; bool first = true;

View file

@ -94,5 +94,5 @@ public:
/// @param value Initial value. Must be a valid time string or empty /// @param value Initial value. Must be a valid time string or empty
/// @param size Initial control size /// @param size Initial control size
/// @param asEnd Treat the time as a line end time (rather than start) for time <-> frame number conversions /// @param asEnd Treat the time as a line end time (rather than start) for time <-> frame number conversions
TimeEdit(wxWindow* parent, wxWindowID id, agi::Context *c, const wxString& value = "", const wxSize& size = wxDefaultSize, bool asEnd = false); TimeEdit(wxWindow* parent, wxWindowID id, agi::Context *c, const wxString& value = wxString(), const wxSize& size = wxDefaultSize, bool asEnd = false);
}; };

View file

@ -75,7 +75,7 @@ public:
/// @param val Initial value to set the associated control to /// @param val Initial value to set the associated control to
/// @param isfloat Allow floats, or just ints? /// @param isfloat Allow floats, or just ints?
/// @param issigned Allow negative numbers? /// @param issigned Allow negative numbers?
explicit NumValidator(wxString val = "", bool isfloat=false, bool issigned=false); explicit NumValidator(wxString val = wxString(), bool isfloat=false, bool issigned=false);
/// Constructor /// Constructor
/// @param val Initial value to set the associated control to /// @param val Initial value to set the associated control to

View file

@ -125,7 +125,7 @@ protected:
/// @brief Commit the current file state /// @brief Commit the current file state
/// @param message Description of changes for undo /// @param message Description of changes for undo
void Commit(wxString message = ""); void Commit(wxString message = wxString());
bool IsDisplayed(AssDialogue *line) const; bool IsDisplayed(AssDialogue *line) const;
/// Get the line's position if it's set, or it's default based on style if not /// Get the line's position if it's set, or it's default based on style if not