File tree Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Expand file tree Collapse file tree 1 file changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -84,22 +84,20 @@ async def longest_prefix_match(
84
84
"""
85
85
node = self .root
86
86
match_length = 0
87
- chunk_hashes = self ._chunk_and_hash (request )
88
87
selected_endpoints = available_endpoints
89
88
90
- for i , chunk_hash in enumerate ( chunk_hashes ):
89
+ for chunk_hash in self . _chunk_and_hash ( request ):
91
90
async with node .lock :
92
- if chunk_hash in node .children :
93
-
94
- node = node .children [chunk_hash ]
95
-
96
- # reached longest prefix match in currently-available endpoints.
97
- if not node .endpoints .intersection (selected_endpoints ):
98
- break
99
-
100
- match_length += self .chunk_size
101
- selected_endpoints = node .endpoints .intersection (selected_endpoints )
102
- else :
103
- break
91
+ node = node .children .get (chunk_hash )
92
+ if not node :
93
+ break
94
+ async with node .lock :
95
+ endpoints = node .endpoints .copy ()
96
+ intersection = endpoints .intersection (selected_endpoints )
97
+ # reached longest prefix match in currently-available endpoints.
98
+ if not intersection :
99
+ break
100
+ match_length += self .chunk_size
101
+ selected_endpoints = intersection
104
102
105
103
return match_length , selected_endpoints
You can’t perform that action at this time.
0 commit comments