Browse Source

UI: Miscellaneous code cleanups

Remove a few unused variables and other minor changes. No functional
differences. Issues detected by PVS Studio.
Richard Stanway 5 years ago
parent
commit
7d3fa7315a

+ 0 - 1
UI/auth-twitch.cpp

@@ -441,7 +441,6 @@ std::shared_ptr<Auth> TwitchAuth::Login(QWidget *parent)
 		return nullptr;
 	}
 
-	std::string error;
 	if (auth->GetChannelInfo()) {
 		return auth;
 	}

+ 8 - 13
UI/importers/classic.cpp

@@ -258,8 +258,6 @@ static Json::object translate_source(const Json &in, const Json &sources)
 		string winClass = in_settings["windowClass"].string_value();
 		string exec = in_settings["executable"].string_value();
 
-		string window = ":" + winClass + ":" + exec;
-
 		settings["window"] = ":" + winClass + ":" + exec;
 
 		translate_bool("captureMouse", in_settings, "capture_cursor",
@@ -298,10 +296,9 @@ static void translate_sc(const Json &in, Json &out)
 	for (size_t i = 0; i < scenes.size(); i++) {
 		Json in_scene = scenes[i];
 
-		if (first_name == "")
+		if (first_name.empty())
 			first_name = in_scene["name"].string_value();
 
-		Json::object settings = Json::object{};
 		Json::array items = Json::array{};
 
 		Json::array sources = in_scene["sources"].array_items();
@@ -391,7 +388,7 @@ static void create_data_item(Json::object &out, const string &line)
 				Json::array new_arr = Json::array{};
 				string str = out[c_name].string_value();
 				create_string_obj(str, new_arr);
-				arr = new_arr;
+				arr = std::move(new_arr);
 			}
 
 			create_string_obj(first, arr);
@@ -408,7 +405,7 @@ static void create_data_item(Json::object &out, const string &line)
 				Json::array new_arr = Json::array{};
 				string str1 = out[c_name].string_value();
 				create_string_obj(str1, new_arr);
-				arr = new_arr;
+				arr = std::move(new_arr);
 			}
 
 			create_string_obj(str, arr);
@@ -431,7 +428,7 @@ static Json::array create_sources(Json::object &out, string &line, string &src)
 
 	line = ReadLine(src);
 	size_t l_len = line.size();
-	while (line != "" && line[l_len - 1] != '}') {
+	while (!line.empty() && line[l_len - 1] != '}') {
 		size_t end_pos = line.find(':');
 
 		if (end_pos == string::npos)
@@ -478,7 +475,7 @@ static Json::object create_object(Json::object &out, string &line, string &src)
 
 	size_t l_len = line.size() - 1;
 
-	while (line != "" && line[l_len] != '}') {
+	while (!line.empty() && line[l_len] != '}') {
 		start_pos = 0;
 		while (line[start_pos] == ' ')
 			start_pos++;
@@ -511,10 +508,8 @@ int ClassicImporter::ImportScenes(const string &path, string &name, Json &res)
 	if (!file_data)
 		return IMPORTER_FILE_WONT_OPEN;
 
-	string sc_name = GetFilenameFromPath(path);
-
-	if (name == "")
-		name = sc_name;
+	if (name.empty())
+		name = GetFilenameFromPath(path);
 
 	Json::object data = Json::object{};
 	data["name"] = name;
@@ -522,7 +517,7 @@ int ClassicImporter::ImportScenes(const string &path, string &name, Json &res)
 	string file = file_data.Get();
 	string line = ReadLine(file);
 
-	while (line != "" && line[0] != '\0') {
+	while (!line.empty() && line[0] != '\0') {
 		string key = line != "global sources : {" ? "scenes"
 							  : "globals";
 

+ 2 - 2
UI/importers/sl.cpp

@@ -318,7 +318,7 @@ static int attempt_import(const Json &root, const string &name, Json &res)
 		while (source_name_exists(out_sources, out_name))
 			out_name = name + "(" + to_string(copy++) + ")";
 
-		if (scene_name == "")
+		if (scene_name.empty())
 			scene_name = out_name;
 
 		string sl_id = scene["id"].string_value();
@@ -399,7 +399,7 @@ string SLImporter::Name(const string &path)
 				string c_name = c["name"].string_value();
 
 				if (c_id == manifest_file) {
-					name = c_name;
+					name = std::move(c_name);
 					name_set = true;
 					break;
 				}

+ 6 - 6
UI/importers/xsplit.cpp

@@ -233,7 +233,7 @@ static void parse_items(QDomNode &item, Json::array &items,
 		}
 
 		name = attr.namedItem("cname").nodeValue().toStdString();
-		if (name == "" || name[0] == '\0')
+		if (name.empty() || name[0] == '\0')
 			name = attr.namedItem("name").nodeValue().toStdString();
 
 		temp_name = name;
@@ -264,7 +264,7 @@ static void parse_items(QDomNode &item, Json::array &items,
 		} else if (type == 2) {
 			QString audio = attr.namedItem("itemaudio").nodeValue();
 
-			if (audio == "") {
+			if (audio.isEmpty()) {
 				source["id"] = "dshow_input";
 			} else {
 				source["id"] = "wasapi_input_capture";
@@ -294,7 +294,7 @@ static void parse_items(QDomNode &item, Json::array &items,
 			QString display =
 				o_attr.namedItem("desktop").nodeValue();
 
-			if (display != "") {
+			if (!display.isEmpty()) {
 				source["id"] = "monitor_capture";
 				int cursor = attr.namedItem("ScrCapShowMouse")
 						     .nodeValue()
@@ -312,7 +312,7 @@ static void parse_items(QDomNode &item, Json::array &items,
 
 				int pos = exec.lastIndexOf('\\');
 
-				if (_class == "") {
+				if (_class.isEmpty()) {
 					_class = "class";
 				}
 
@@ -421,7 +421,7 @@ static Json::object parse_scenes(QDomElement &scenes)
 			QString name = attr.namedItem("name").nodeValue();
 			QString id = attr.namedItem("id").nodeValue();
 
-			if (first == "")
+			if (first.isEmpty())
 				first = name;
 
 			Json out = Json::object{
@@ -492,7 +492,7 @@ bool XSplitImporter::Check(const string &path)
 	string pos = file_data.Get();
 
 	string line = ReadLine(pos);
-	while (line != "") {
+	while (!line.empty()) {
 		if (line.substr(0, 5) == "<?xml") {
 			line = ReadLine(pos);
 		} else {

+ 2 - 2
UI/window-basic-auto-config-test.cpp

@@ -458,8 +458,8 @@ void AutoConfigTestPage::TestBandwidthThread()
 		}
 	}
 
-	wiz->server = bestServer;
-	wiz->serverName = bestServerName;
+	wiz->server = std::move(bestServer);
+	wiz->serverName = std::move(bestServerName);
 	wiz->idealBitrate = bestBitrate;
 
 	QMetaObject::invokeMethod(this, "NextStage");

+ 11 - 16
UI/window-basic-main.cpp

@@ -1939,14 +1939,11 @@ void OBSBasic::OnFirstLoad()
 	/* Attempt to load init screen if available */
 	if (cef) {
 		WhatsNewInfoThread *wnit = new WhatsNewInfoThread();
-		if (wnit) {
-			connect(wnit, &WhatsNewInfoThread::Result, this,
+		connect(wnit, &WhatsNewInfoThread::Result, this,
 				&OBSBasic::ReceivedIntroJson);
-		}
-		if (wnit) {
-			introCheckThread.reset(wnit);
-			introCheckThread->start();
-		}
+
+		introCheckThread.reset(wnit);
+		introCheckThread->start();
 	}
 #endif
 
@@ -2061,14 +2058,13 @@ void OBSBasic::ReceivedIntroJson(const QString &text)
 
 	WhatsNewBrowserInitThread *wnbit =
 		new WhatsNewBrowserInitThread(QT_UTF8(info_url.c_str()));
-	if (wnbit) {
-		connect(wnbit, &WhatsNewBrowserInitThread::Result, this,
+
+	connect(wnbit, &WhatsNewBrowserInitThread::Result, this,
 			&OBSBasic::ShowWhatsNew);
-	}
-	if (wnbit) {
-		whatsNewInitThread.reset(wnbit);
-		whatsNewInitThread->start();
-	}
+
+	whatsNewInitThread.reset(wnbit);
+	whatsNewInitThread->start();
+
 #else
 	UNUSED_PARAMETER(text);
 #endif
@@ -7051,8 +7047,7 @@ OBSProjector *OBSBasic::OpenProjector(obs_source_t *source, int monitor,
 	OBSProjector *projector =
 		new OBSProjector(nullptr, source, monitor, type);
 
-	if (projector)
-		projectors.emplace_back(projector);
+	projectors.emplace_back(projector);
 
 	return projector;
 }

+ 1 - 1
UI/window-importer.cpp

@@ -283,7 +283,7 @@ void ImporterModel::checkInputPath(int row)
 		std::string program = DetectProgram(entry.path.toStdString());
 		entry.program = QTStr(program.c_str());
 
-		if (program == "") {
+		if (program.empty()) {
 			entry.selected = false;
 		} else {
 			std::string name =