mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-01 03:48:43 +00:00
(svn r20951) -Codechange: Add SmallMap::Contains() and use it.
This commit is contained in:
parent
82d4ffacff
commit
98250ad8da
@ -318,7 +318,7 @@ struct AISettingsWindow : public Window {
|
||||
SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
|
||||
} else {
|
||||
DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > (*it).min_value, editable && current_value < (*it).max_value);
|
||||
if (it->labels != NULL && it->labels->Find(current_value) != it->labels->End()) {
|
||||
if (it->labels != NULL && it->labels->Contains(current_value)) {
|
||||
SetDParam(idx++, STR_JUST_RAW_STRING);
|
||||
SetDParamStr(idx++, it->labels->Find(current_value)->second);
|
||||
} else {
|
||||
|
@ -307,7 +307,8 @@ SQInteger AIInfo::AddLabels(HSQUIRRELVM vm)
|
||||
int key = atoi(key_string + 1);
|
||||
const char *label = SQ2OTTD(sq_label);
|
||||
|
||||
if (config->labels->Find(key) == config->labels->End()) config->labels->Insert(key, strdup(label));
|
||||
/* !Contains() prevents strdup from leaking. */
|
||||
if (!config->labels->Contains(key)) config->labels->Insert(key, strdup(label));
|
||||
|
||||
sq_pop(vm, 2);
|
||||
}
|
||||
|
@ -54,6 +54,16 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
|
||||
return this->End();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether a key is assigned in this map.
|
||||
* @param key key to test
|
||||
* @return true iff the item is present
|
||||
*/
|
||||
FORCEINLINE bool Contains(const T &key)
|
||||
{
|
||||
return this->Find(key) != this->End();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes given pair from this map
|
||||
* @param pair pair to remove
|
||||
@ -90,7 +100,7 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
|
||||
*/
|
||||
FORCEINLINE bool Insert(const T &key, const U &data)
|
||||
{
|
||||
if (this->Find(key) != this->End()) return false;
|
||||
if (this->Contains(key)) return false;
|
||||
Pair *n = this->Append();
|
||||
n->first = key;
|
||||
n->second = data;
|
||||
|
@ -212,7 +212,7 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *
|
||||
* ofcourse totally unneeded ;) */
|
||||
if (sockets != NULL) {
|
||||
NetworkAddress address(runp->ai_addr, (int)runp->ai_addrlen);
|
||||
if (sockets->Find(address) != sockets->End()) continue;
|
||||
if (sockets->Contains(address)) continue;
|
||||
}
|
||||
sock = func(runp);
|
||||
if (sock == INVALID_SOCKET) continue;
|
||||
|
@ -258,7 +258,7 @@ struct NewGRFParametersWindow : public Window {
|
||||
DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, current_value > par_info->min_value, current_value < par_info->max_value);
|
||||
SetDParam(2, STR_JUST_INT);
|
||||
SetDParam(3, current_value);
|
||||
if (par_info->value_names.Find(current_value) != par_info->value_names.End()) {
|
||||
if (par_info->value_names.Contains(current_value)) {
|
||||
const char *label = GetGRFStringFromGRFText(par_info->value_names.Find(current_value)->second);
|
||||
if (label != NULL) {
|
||||
SetDParam(2, STR_JUST_RAW_STRING);
|
||||
|
Loading…
Reference in New Issue
Block a user