Opened 15 years ago

Closed 15 years ago

#932 closed feature-request (Fixed)

[PATCH] Optimize ti_name even more

Reported by: Plisk Owned by: andar
Priority: minor Milestone:
Component: Core Version: 1.1.7
Keywords: Cc:


Looking through pydoc str accidentally gave a sight to optional arg to str.split(). So here are some more tests

import os

def f1(name):
    first_slash_index = name.find("/")
    if first_slash_index != -1:
        name = name[:first_slash_index]
    return name

def f2(name):
    name = os.path.split(name)[0]
    return name

def f3(name):
    name = name.split("/")[0]
    return name

def f4(name):
    name = name.split("/", 1)[0]
    return name

if __name__ == "__main__":
    import timeit
    print timeit.Timer("f1('11/22/33/44/55/66/test.txt')", "from __main__ import f1").timeit()
    print timeit.Timer("f2('11/22/33/44/55/66/test.txt')", "from __main__ import f2").timeit()
    print timeit.Timer("f3('11/22/33/44/55/66/test.txt')", "from __main__ import f3").timeit()
    print timeit.Timer("f4('11/22/33/44/55/66/test.txt')", "from __main__ import f4").timeit()


And a patch based on this

Index: deluge/core/
--- deluge/core/      (revision 5251)
+++ deluge/core/      (working copy)
@@ -621,7 +584,7 @@

         def ti_name():
             if self.handle.has_metadata():
-                name = self.torrent_info.file_at(0).path.split("/")[0]
+                name = self.torrent_info.file_at(0).path.split("/", 1)[0]
                     return name.decode("utf8", "ignore")
                 except UnicodeDecodeError:

Change History (1)

comment:1 Changed 15 years ago by andar

  • Resolution set to fixed
  • Status changed from new to closed

Committed [5253]

Note: See TracTickets for help on using tickets.