From 8cd3ab8cb81daff492989c1260b9559e3d90004c Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Wed, 13 Aug 2014 06:10:48 +0000 Subject: [PATCH] Remove unnecessary file existence check in GMenu2X::readTmp() A file existence check is already performed, atomically with respect to the filesystem, by ifstream's constructor. The result of this check is available using ifstream::is_open(). --- src/gmenu2x.cpp | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 69a1554..d9261a7 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -537,27 +537,25 @@ void GMenu2X::writeSkinConfig() { void GMenu2X::readTmp() { lastSelectorElement = -1; - if (fileExists("/tmp/gmenu2x.tmp")) { - ifstream inf("/tmp/gmenu2x.tmp", ios_base::in); - if (inf.is_open()) { - string line; - string section = ""; - while (getline(inf, line, '\n')) { - string::size_type pos = line.find("="); - string name = trim(line.substr(0,pos)); - string value = trim(line.substr(pos+1,line.length())); + ifstream inf("/tmp/gmenu2x.tmp", ios_base::in); + if (inf.is_open()) { + string line; + string section = ""; + while (getline(inf, line, '\n')) { + string::size_type pos = line.find("="); + string name = trim(line.substr(0,pos)); + string value = trim(line.substr(pos+1,line.length())); - if (name=="section") - menu->setSectionIndex(atoi(value.c_str())); - else if (name=="link") - menu->setLinkIndex(atoi(value.c_str())); - else if (name=="selectorelem") - lastSelectorElement = atoi(value.c_str()); - else if (name=="selectordir") - lastSelectorDir = value; - } - inf.close(); + if (name=="section") + menu->setSectionIndex(atoi(value.c_str())); + else if (name=="link") + menu->setLinkIndex(atoi(value.c_str())); + else if (name=="selectorelem") + lastSelectorElement = atoi(value.c_str()); + else if (name=="selectordir") + lastSelectorDir = value; } + inf.close(); } }