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

View File

@ -96,7 +96,7 @@ public:
class AssDialogueBlockPlain : public AssDialogueBlock {
public:
ASS_BlockType GetType() { return BLOCK_PLAIN; }
AssDialogueBlockPlain(wxString const& text = "") : AssDialogueBlock(text) { }
AssDialogueBlockPlain(wxString const& text = wxString()) : AssDialogueBlock(text) { }
};
/// @class AssDialogueBlockDrawing
@ -109,7 +109,7 @@ public:
int Scale;
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);
};
@ -119,7 +119,7 @@ public:
/// DOCME
class AssDialogueBlockOverride : public AssDialogueBlock {
public:
AssDialogueBlockOverride(wxString const& text = "") : AssDialogueBlock(text) { }
AssDialogueBlockOverride(wxString const& text = wxString()) : AssDialogueBlock(text) { }
~AssDialogueBlockOverride();
/// DOCME

View File

@ -82,7 +82,7 @@ public:
/// Group it belongs to, e.g. "[Events]"
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() { }
/// Create a copy of this entry

View File

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

View File

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

View File

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

View File

@ -136,7 +136,7 @@ public:
ColorPickerRecent(wxWindow *parent, int cols, int rows, int cellsize);
/// 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
wxString StoreToString();
/// Add a color to the beginning of the recent list

View File

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

View File

@ -57,5 +57,5 @@ public:
void SetUnicodeStyling(int start,int length,int style);
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 alt Alternate name of the tag, if any
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--) {
AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(line.Blocks[i]);
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) {
// Prepare text
wxString data = "";
wxString data;
AssDialogue *cur;
int nrows = target.Count();
bool first = true;

View File

@ -94,5 +94,5 @@ public:
/// @param value Initial value. Must be a valid time string or empty
/// @param size Initial control size
/// @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 isfloat Allow floats, or just ints?
/// @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
/// @param val Initial value to set the associated control to

View File

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