diff options
author | michi_cc <michi_cc@openttd.org> | 2015-05-17 19:49:35 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2015-05-17 19:49:35 +0000 |
commit | 95cb7c8692ab9527f05a7bef743f6a6a18b7df17 (patch) | |
tree | f285c527da15263004638cec6dbdb894f4dc27ef /src/network | |
parent | 514da346bdfb94422d0e0c57eeaebea80b3db071 (diff) | |
download | openttd-95cb7c8692ab9527f05a7bef743f6a6a18b7df17.tar.xz |
(svn r27288) -Fix: Slow network content GUI in MSVC Debug builds due to repeated string resolving.
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network_content_gui.cpp | 21 | ||||
-rw-r--r-- | src/network/network_content_gui.h | 2 |
2 files changed, 18 insertions, 5 deletions
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 1b4b7e030..7ee1dbd99 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -304,6 +304,8 @@ class NetworkContentListWindow : public Window, ContentCallback { uint filesize_sum; ///< The sum of all selected file sizes Scrollbar *vscroll; ///< Cache of the vertical scrollbar + static char content_type_strs[CONTENT_TYPE_END][64]; ///< Cached strings for all content types. + /** Search external websites for content */ void OpenExternalSearch() { @@ -401,11 +403,7 @@ class NetworkContentListWindow : public Window, ContentCallback { { int r = 0; if ((*a)->type != (*b)->type) { - char a_str[64]; - char b_str[64]; - GetString(a_str, STR_CONTENT_TYPE_BASE_GRAPHICS + (*a)->type - CONTENT_TYPE_BASE_GRAPHICS, lastof(a_str)); - GetString(b_str, STR_CONTENT_TYPE_BASE_GRAPHICS + (*b)->type - CONTENT_TYPE_BASE_GRAPHICS, lastof(b_str)); - r = strnatcmp(a_str, b_str); + r = strnatcmp(content_type_strs[(*a)->type], content_type_strs[(*b)->type]); } if (r == 0) r = NameSorter(a, b); return r; @@ -469,6 +467,7 @@ class NetworkContentListWindow : public Window, ContentCallback { this->vscroll->ScrollTowards(this->list_pos); } + friend void BuildContentTypeStringList(); public: /** * Create the content list window. @@ -968,6 +967,18 @@ NetworkContentListWindow::GUIContentList::FilterFunction * const NetworkContentL &TagNameFilter, }; +char NetworkContentListWindow::content_type_strs[CONTENT_TYPE_END][64]; + +/** + * Build array of all strings corresponding to the content types. + */ +void BuildContentTypeStringList() +{ + for (int i = CONTENT_TYPE_BEGIN; i < CONTENT_TYPE_END; i++) { + GetString(NetworkContentListWindow::content_type_strs[i], STR_CONTENT_TYPE_BASE_GRAPHICS + i - CONTENT_TYPE_BASE_GRAPHICS, lastof(NetworkContentListWindow::content_type_strs[i])); + } +} + /** The widgets for the content list. */ static const NWidgetPart _nested_network_content_list_widgets[] = { NWidget(NWID_HORIZONTAL), diff --git a/src/network/network_content_gui.h b/src/network/network_content_gui.h index 212fcec04..139701001 100644 --- a/src/network/network_content_gui.h +++ b/src/network/network_content_gui.h @@ -43,4 +43,6 @@ public: virtual void OnDownloadProgress(const ContentInfo *ci, int bytes); }; +void BuildContentTypeStringList(); + #endif /* NETWORK_CONTENT_GUI_H */ |