Skip to content

Commit d1ded03

Browse files
committed
Extract namedtuple to global context to avoid re-creation on every function call
1 parent 16c4cef commit d1ded03

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

giturlparse/parser.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
import collections
2424
import re
2525

26+
Parsed = collections.namedtuple('Parsed', [
27+
'pathname',
28+
'protocols',
29+
'protocol',
30+
'href',
31+
'resource',
32+
'user',
33+
'port',
34+
'name',
35+
'owner',
36+
])
37+
2638

2739
class ParserError(Exception):
2840
""" Error raised when a URL can't be parsed. """
@@ -37,19 +49,6 @@ class Parser(object):
3749
def __init__(self, url):
3850
self._url = url
3951

40-
def get_parsed(self):
41-
return collections.namedtuple('Parsed', [
42-
'pathname',
43-
'protocols',
44-
'protocol',
45-
'href',
46-
'resource',
47-
'user',
48-
'port',
49-
'name',
50-
'owner',
51-
])
52-
5352
def parse(self):
5453
"""
5554
Parses a GIT URL and returns an object. Raises an exception on invalid
@@ -102,9 +101,7 @@ def parse(self):
102101
msg = "Invalid URL '{}'".format(self._url)
103102
raise ParserError(msg)
104103

105-
p = self.get_parsed()
106-
107-
return p(**d)
104+
return Parsed(**d)
108105

109106
def _get_protocols(self):
110107
try:

0 commit comments

Comments
 (0)