heredoc_unindent 1.0.6 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/History.rdoc +12 -0
- data/README.rdoc +22 -8
- data/Rakefile +1 -1
- data/lib/heredoc_unindent.rb +36 -3
- data/test/test_heredoc_unindent.rb +1 -1
- metadata +9 -5
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
=== 1.1.0 / 2011-01-29
|
2
|
+
|
3
|
+
* 3 minor enhancements
|
4
|
+
|
5
|
+
* Added a new #unindent_base implementation
|
6
|
+
* 50--62% faster on ruby-1.9.2-p136, jruby-1.5.6 and rbx-1.2.0
|
7
|
+
* 10--20% slower in ruby-1.8.7-p330 and ree-1.8.7-2010.02
|
8
|
+
* so the old one is kept and the fastest for your VM is automatically chosen on load-time
|
9
|
+
* Created a couple scripts to benchmark unindenting implementations
|
10
|
+
* available on the GitHub repository, but not included in the gem
|
11
|
+
* Improved ALTERNATIVES section of README with performance results extracted from benchmarking
|
12
|
+
|
1
13
|
=== 1.0.6 / 2011-01-27
|
2
14
|
|
3
15
|
* 1 minor enhancement
|
data/README.rdoc
CHANGED
@@ -70,14 +70,28 @@ Based on the answer by Rene Saarsoo to the question
|
|
70
70
|
|
71
71
|
== ALTERNATIVES
|
72
72
|
|
73
|
-
Despite minor API differences
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
73
|
+
Despite minor API differences or edge-case behaviour, the following gems
|
74
|
+
implement equivalent unindenting functionality:
|
75
|
+
|
76
|
+
1. {outdent}[http://rubygems.org/gems/outdent] (formerly {unindentable}[http://rubygems.org/gems/unindentable])
|
77
|
+
2. {unindent}[http://rubygems.org/gems/unindent]
|
78
|
+
3. {indentation}[http://rubygems.org/gems/indentation] -- this gem has a broader scope, besides String#reset_indentation
|
79
|
+
|
80
|
+
=== So why another one?
|
81
|
+
|
82
|
+
Well, the Fact is that the author only found about the other gems after he had
|
83
|
+
already implemented heredoc_unindent. And, frankly, that was fortunate:
|
84
|
+
benchmarking revealed that heredoc_unindent is by far the most efficient, both
|
85
|
+
in space (memory) and time (cycles).
|
86
|
+
|
87
|
+
=== Efficiency!
|
88
|
+
|
89
|
+
Depending on the Ruby implementation, heredoc_unindent is is about *1.6--2.4x*
|
90
|
+
*faster* than {unindent}[http://rubygems.org/gems/unindent], *1.9--6.6x*
|
91
|
+
*faster* than {indentation}[http://rubygems.org/gems/indentation],
|
92
|
+
and *4--19x* *faster* than {outdent}[http://rubygems.org/gems/outdent].
|
93
|
+
In addition, heredoc_unindent has the *lowest* *memory* *consumption*,
|
94
|
+
requiring only between a fifth and a sixth of the competitors.
|
81
95
|
|
82
96
|
== LICENSE:
|
83
97
|
|
data/Rakefile
CHANGED
data/lib/heredoc_unindent.rb
CHANGED
@@ -8,23 +8,56 @@ module CoreExt
|
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
|
-
# Actual
|
11
|
+
# Actual implementations of the unindentation mechanism,
|
12
12
|
# both for in and out-of-place processing.
|
13
13
|
#
|
14
|
+
# @note The only reason there are two implementations is because the new
|
15
|
+
# one is slower than the old one on MRI and REE 1.8.7. The fastest
|
16
|
+
# implementation is automatically chosen based on the virtual
|
17
|
+
# machine being executed.
|
18
|
+
#
|
14
19
|
# @param [Boolean] warn_first_not_min
|
15
20
|
# @param [Boolean] in_place
|
16
21
|
# @return [String, nil]
|
17
22
|
#
|
18
|
-
|
23
|
+
|
24
|
+
# about 50% faster in jruby, 56% in ruby-1.9.2, 62% in rbx-1.2.0 (new vs old)
|
25
|
+
#
|
26
|
+
def unindent_base_new(in_place, warn_first_not_min)
|
27
|
+
m_first = nil
|
28
|
+
m_min = nil
|
29
|
+
self.scan(/^\s*/) do |m|
|
30
|
+
ms = m.size
|
31
|
+
m_first ||= ms
|
32
|
+
m_min = ms if !m_min || ms < m_min
|
33
|
+
# break if ms == 0 ## only worth if the probability of marginless line above certain threshold
|
34
|
+
end
|
35
|
+
if m_first != m_min && warn_first_not_min
|
36
|
+
puts "warning: margin of the first line differs from minimum margin"
|
37
|
+
end
|
38
|
+
return in_place ? nil : self.dup unless m_min > 0
|
39
|
+
re = Regexp.new('^\s{' + m_min.to_s + '}' )
|
40
|
+
in_place ? gsub!(re, '') : gsub(re, '')
|
41
|
+
end
|
42
|
+
|
43
|
+
# about 10% faster in ree, 20% in ruby-1.8.7 (old vs new)
|
44
|
+
#
|
45
|
+
def unindent_base_old(in_place, warn_first_not_min)
|
19
46
|
margins = self.scan(/^\s*/).map(&:size)
|
20
47
|
margins_min = margins.min
|
21
48
|
if margins.first != margins_min && warn_first_not_min
|
22
49
|
puts "warning: margin of the first line differs from minimum margin"
|
23
50
|
end
|
24
51
|
return in_place ? nil : self.dup unless margins_min != 0
|
25
|
-
re = Regexp.new('^\s{
|
52
|
+
re = Regexp.new('^\s{' + margins_min.to_s + '}' )
|
26
53
|
in_place ? gsub!(re, '') : gsub(re, '')
|
27
54
|
end
|
55
|
+
|
56
|
+
if RUBY_VERSION >= '1.9' || defined?(RUBY_DESCRIPTION) && (RUBY_DESCRIPTION =~ /jruby/i || RUBY_DESCRIPTION =~ /rubinius/i)
|
57
|
+
alias unindent_base unindent_base_new
|
58
|
+
else
|
59
|
+
alias unindent_base unindent_base_old
|
60
|
+
end
|
28
61
|
|
29
62
|
public
|
30
63
|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heredoc_unindent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 1
|
8
|
+
- 1
|
7
9
|
- 0
|
8
|
-
|
9
|
-
version: 1.0.6
|
10
|
+
version: 1.1.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Adriano Mitre
|
@@ -35,7 +36,7 @@ cert_chain:
|
|
35
36
|
9u8N6mQNneIVRh6Xfdko/Q==
|
36
37
|
-----END CERTIFICATE-----
|
37
38
|
|
38
|
-
date: 2011-01-
|
39
|
+
date: 2011-01-29 00:00:00 -02:00
|
39
40
|
default_executable:
|
40
41
|
dependencies:
|
41
42
|
- !ruby/object:Gem::Dependency
|
@@ -46,6 +47,7 @@ dependencies:
|
|
46
47
|
requirements:
|
47
48
|
- - ">="
|
48
49
|
- !ruby/object:Gem::Version
|
50
|
+
hash: 47
|
49
51
|
segments:
|
50
52
|
- 2
|
51
53
|
- 8
|
@@ -97,6 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
99
|
requirements:
|
98
100
|
- - ">="
|
99
101
|
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
100
103
|
segments:
|
101
104
|
- 0
|
102
105
|
version: "0"
|
@@ -105,13 +108,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
108
|
requirements:
|
106
109
|
- - ">="
|
107
110
|
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
108
112
|
segments:
|
109
113
|
- 0
|
110
114
|
version: "0"
|
111
115
|
requirements: []
|
112
116
|
|
113
117
|
rubyforge_project: heredoc_unindent
|
114
|
-
rubygems_version: 1.
|
118
|
+
rubygems_version: 1.4.1
|
115
119
|
signing_key:
|
116
120
|
specification_version: 3
|
117
121
|
summary: This gem removes common margin from indented strings, such as the ones produced by indented heredocs
|
metadata.gz.sig
CHANGED
Binary file
|