Use try-except instead of if statement to gain a little performance

This commit is contained in:
Calum Lind 2012-12-07 10:48:56 +00:00
commit 2a8b8e93da

View file

@ -571,11 +571,10 @@ class TorrentManager(component.Component):
:raises InvalidTorrentError: if the torrent_id is not in the session
"""
if torrent_id not in self.torrents:
raise InvalidTorrentError("torrent_id not in session")
try:
torrent_name = self.torrents[torrent_id].get_status(["name"])["name"]
except KeyError:
raise InvalidTorrentError("torrent_id not in session")
# Emit the signal to the clients
component.get("EventManager").emit(PreTorrentRemovedEvent(torrent_id))