You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/protocol/http2/dependency.rb
+34-7Lines changed: 34 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,10 @@ def <=> other
58
58
@weight <=> other.weight
59
59
end
60
60
61
+
def == other
62
+
@id == other.id
63
+
end
64
+
61
65
# The connection this stream belongs to.
62
66
attr:connection
63
67
@@ -101,13 +105,30 @@ def add_child(dependency)
101
105
102
106
dependency.parent=self
103
107
104
-
self.clear_cache!
108
+
if@ordered_children
109
+
# Binary search for insertion point:
110
+
index=@ordered_children.bsearch_indexdo |child|
111
+
child.weight >= dependency.weight
112
+
end
113
+
114
+
ifindex
115
+
@ordered_children.insert(index,dependency)
116
+
else
117
+
@ordered_children.push(dependency)
118
+
end
119
+
120
+
@total_weight += dependency.weight
121
+
end
105
122
end
106
123
107
124
defremove_child(dependency)
108
125
@children&.delete(dependency.id)
109
126
110
-
self.clear_cache!
127
+
if@ordered_children
128
+
# Don't do a linear search here, it can be slow. Instead, the child's parent will be set to `nil`, and we check this in {#consume_window} using `delete_if`.
129
+
# @ordered_children.delete(dependency)
130
+
@total_weight -= dependency.weight
131
+
end
111
132
end
112
133
113
134
# An exclusive flag allows for the insertion of a new level of dependencies. The exclusive flag causes the stream to become the sole dependency of its parent stream, causing other dependencies to become dependent on the exclusive stream.
@@ -195,11 +216,17 @@ def consume_window(size)
195
216
end
196
217
197
218
# Otherwise, allow the dependent children to use up the available window:
0 commit comments