@@ -1365,7 +1365,7 @@ defmodule Mint.HTTP2 do
1365
1365
end
1366
1366
1367
1367
defp add_pseudo_headers ( headers , conn , method , path ) do
1368
- if is_method ?( method , ~c " CONNECT" ) do
1368
+ if same_method ?( method , "CONNECT" ) do
1369
1369
[
1370
1370
{ ":method" , method } ,
1371
1371
{ ":authority" , conn . authority }
@@ -1382,19 +1382,20 @@ defmodule Mint.HTTP2 do
1382
1382
end
1383
1383
end
1384
1384
1385
- @ spec is_method? ( proposed :: binary ( ) , method :: charlist ( ) ) :: boolean ( )
1386
- defp is_method? ( << >> , [ ] ) , do: true
1385
+ # same_method?/2 is pretty optimized, so bench before changing.
1387
1386
1388
- defp is_method? ( << char , rest_bin :: binary >> , [ char | rest_list ] ) do
1389
- is_method? ( rest_bin , rest_list )
1390
- end
1387
+ # Same binary, which is a common case.
1388
+ defp same_method? ( bin , bin ) , do: true
1391
1389
1392
- defp is_method? ( << lower_char , rest_bin :: binary >> , [ char | rest_list ] )
1393
- when lower_char >= ?a and lower_char <= ?z and lower_char - 32 == char do
1394
- is_method? ( rest_bin , rest_list )
1395
- end
1390
+ # Get out early if the size is different, these can't be the same.
1391
+ defp same_method? ( bin1 , bin2 ) when byte_size ( bin1 ) != byte_size ( bin2 ) , do: false
1392
+
1393
+ defp same_method? ( << ch , rest1 :: binary >> , << ch , rest2 :: binary >> ) , do: same_method? ( rest1 , rest2 )
1394
+
1395
+ defp same_method? ( << lower , rest1 :: binary >> , << char , rest2 :: binary >> ) when lower - 32 == char ,
1396
+ do: same_method? ( rest1 , rest2 )
1396
1397
1397
- defp is_method? ( _proposed , _method ) , do: false
1398
+ defp same_method? ( _method1 , _method2 ) , do: false
1398
1399
1399
1400
defp sort_pseudo_headers_to_front ( headers ) do
1400
1401
Enum . sort_by ( headers , fn { key , _value } ->
0 commit comments