Skip to content

Commit

Permalink
Merge pull request #167 from igrigorik/refactor-task
Browse files Browse the repository at this point in the history
Refactor generate_huffman_table task
  • Loading branch information
mullermp authored Jun 10, 2024
2 parents e83ebe8 + 725d98a commit dfe8629
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ AllCops:

Layout/IndentHeredoc:
Exclude:
- 'lib/tasks/generate_huffman_table.rb'
- 'tasks/generate_huffman_table.rb'
- 'example/*'

Metrics/LineLength:
Expand Down
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Style/Documentation:
- 'test/**/*'
- 'example/helper.rb'
- 'example/upgrade_server.rb'
- 'lib/tasks/generate_huffman_table.rb'
- 'tasks/generate_huffman_table.rb'

# Offense count: 3
# Cop supports --auto-correct.
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'yard'
require 'open3'
require_relative 'lib/tasks/generate_huffman_table'

require_relative 'tasks/generate_huffman_table'

RSpec::Core::RakeTask.new(:spec) do |t|
t.exclude_pattern = './spec/hpack_test_spec.rb'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require_relative '../lib/http/2/huffman'

# TODO: Currently, regenerating this table will produce something different from
# the table shipped with this gem. It is however stable.
desc 'Generate Huffman precompiled table in huffman_statemachine.rb'
task :generate_table do
task :generate_huffman_table do
HuffmanTable::Node.generate_state_table
end

require_relative '../http/2/huffman'

# @private
module HuffmanTable
BITS_AT_ONCE = HTTP2::Header::Huffman::BITS_AT_ONCE
EOS = 256
Expand Down Expand Up @@ -102,7 +103,7 @@ def self.generate_state_table
id += 1
end

File.open(File.expand_path('../http/2/huffman_statemachine.rb', File.dirname(__FILE__)), 'w') do |f|
File.open(File.expand_path('../lib/http/2/huffman_statemachine.rb', File.dirname(__FILE__)), 'w') do |f|
f.print <<HEADER
# Machine generated Huffman decoder state machine.
# DO NOT EDIT THIS FILE.
Expand Down

0 comments on commit dfe8629

Please sign in to comment.