Branch: master

09835dce 2019-07-05 04:23:08 Michele Calgaro
tdehw: improved code for mount table.

Signed-off-by: Michele Calgaro <michele.calgaro@...>
M tdecore/tdehw/tdehardwaredevices.cpp
M tdecore/tdehw/tdehardwaredevices.h

tdecore/tdehw/tdehardwaredevices.cpp

diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp
index 6267ad0..a1c8848 100644
--- a/tdecore/tdehw/tdehardwaredevices.cpp
+++ b/tdecore/tdehw/tdehardwaredevices.cpp
@@ -154,7 +154,10 @@
 		if ( file.open( IO_ReadOnly ) ) {
 			TQTextStream stream( &file );
 			while ( !stream.atEnd() ) {
-				m_mountTable.append(stream.readLine());
+				TQString line = stream.readLine();
+				if (!line.isEmpty()) {
+					m_mountTable[line] = true;
+				}
 			}
 			file.close();
 		}
@@ -921,7 +924,7 @@
 	// Detect what changed between the old mount table and the new one,
 	// and emit appropriate events
 
-	TQStringList deletedEntries = m_mountTable;
+	TQMap<TQString, bool> deletedEntries = m_mountTable;
 
 	// Read in the new mount table
 	m_mountTable.clear();
@@ -929,31 +932,26 @@
 	if ( file.open( IO_ReadOnly ) ) {
 		TQTextStream stream( &file );
 		while ( !stream.atEnd() ) {
-			m_mountTable.append(stream.readLine());
+			TQString line = stream.readLine();
+			if (!line.isEmpty()) {
+				m_mountTable[line] = true;
+			}
 		}
 		file.close();
 	}
-
-	TQStringList addedEntries = m_mountTable;
+	TQMap<TQString, bool> addedEntries = m_mountTable;
 
 	// Remove all entries that are identical in both tables
-	processModifiedMounts_removeagain:
-	for ( TQStringList::Iterator delit = deletedEntries.begin(); delit != deletedEntries.end(); ++delit ) {
-		for ( TQStringList::Iterator addit = addedEntries.begin(); addit != addedEntries.end(); ++addit ) {
-			if ((*delit) == (*addit)) {
-				deletedEntries.remove(delit);
-				addedEntries.remove(addit);
-				// Reset iterators to prevent bugs/crashes
-				// FIXME
-				// Is there any way to completely reset both loops without using goto?
-				goto processModifiedMounts_removeagain;
-			}
+	for ( TQMap<TQString, bool>::ConstIterator mtIt = m_mountTable.begin(); mtIt != m_mountTable.end(); ++mtIt ) {
+		if (deletedEntries.contains(mtIt.key())) {
+			deletedEntries.remove(mtIt.key());
+			addedEntries.remove(mtIt.key());
 		}
 	}
 
-	TQStringList::Iterator it;
+	TQMap<TQString, bool>::Iterator it;
 	for ( it = addedEntries.begin(); it != addedEntries.end(); ++it ) {
-		TQStringList mountInfo = TQStringList::split(" ", (*it), true);
+		TQStringList mountInfo = TQStringList::split(" ", it.key(), true);
 		// Try to find a device that matches the altered node
 		TDEGenericDevice* hwdevice = findByDeviceNode(*mountInfo.at(0));
 		if (hwdevice) {
@@ -974,7 +972,7 @@
 		}
 	}
 	for ( it = deletedEntries.begin(); it != deletedEntries.end(); ++it ) {
-		TQStringList mountInfo = TQStringList::split(" ", (*it), true);
+		TQStringList mountInfo = TQStringList::split(" ", it.key(), true);
 		// Try to find a device that matches the altered node
 		TDEGenericDevice* hwdevice = findByDeviceNode(*mountInfo.at(0));
 		if (hwdevice) {

tdecore/tdehw/tdehardwaredevices.h

diff --git a/tdecore/tdehw/tdehardwaredevices.h b/tdecore/tdehw/tdehardwaredevices.h
index 2d5aeaf..44b50e3 100644
--- a/tdecore/tdehw/tdehardwaredevices.h
+++ b/tdecore/tdehw/tdehardwaredevices.h
@@ -305,7 +305,7 @@
 		TQSocketNotifier* m_devScanNotifier;
 		TQSocketNotifier* m_mountScanNotifier;
 
-		TQStringList m_mountTable;
+		TQMap<TQString, bool> m_mountTable;
 		TQStringList m_cpuInfo;
 
 		TDEDeviceIDMap* pci_id_map;