sprockets 3.6.0 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprockets might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1eef394792f4af6343438fcc3666a88ca893348
4
- data.tar.gz: 464e323e318b96534f12621a3f1a5dfc9a024425
3
+ metadata.gz: 395f97699c07aab98cec80882a5e7f3737aaaa6c
4
+ data.tar.gz: 30beb1d71c6bfa3c26472dc5d9e30a0e9d6a077f
5
5
  SHA512:
6
- metadata.gz: 446a6718c9ae7f0e94e57672680c7bbb2233855000dd813d3dc1867d0d3c6f12f3dcb43abe21f9a72bfcc05bff7524b9030eb771c342d4ea65fdde1169887f21
7
- data.tar.gz: e49c3925afb5988848f46439b1e9c3b5334932e599c13398f0a7a6a312dde2f228c0e679bd8fc898e80dd1861bc4fcfedfd807a9872b91b2af14be210870ab7d
6
+ metadata.gz: c7f9e96886a62cc1704af19e305beb4e6b1ae49cabcd2c23d3464d91694c1798920e9aba2658a1725e1628a0689d11ea83d03839e5254de21d81a9d13d1423da
7
+ data.tar.gz: 576f6ecb35fa61eeef7f14c22a8de476f916cd704865185abfd11170375df51058df781b4db57d98f463704ad6cf48b5f7a0af130648bfa5b26d8bac89d4eb2f
@@ -1,3 +1,7 @@
1
+ **3.6.1** (June 17, 2016)
2
+
3
+ * Some performance improvements.
4
+
1
5
  **3.6.0** (April 6, 2016)
2
6
 
3
7
  * Add `Manifest#find_sources` to return the source of the compiled assets.
@@ -36,7 +36,6 @@ module Sprockets
36
36
  # (default: 1000).
37
37
  def initialize(root, max_size = DEFAULT_MAX_SIZE, logger = self.class.default_logger)
38
38
  @root = root
39
- @size = find_caches.inject(0) { |n, (_, stat)| n + stat.size }
40
39
  @max_size = max_size
41
40
  @gc_size = max_size * 0.75
42
41
  @logger = logger
@@ -107,11 +106,11 @@ module Sprockets
107
106
  # Write data
108
107
  PathUtils.atomic_write(path) do |f|
109
108
  f.write(raw)
110
- @size += f.size unless exists
109
+ @size = size + f.size unless exists
111
110
  end
112
111
 
113
112
  # GC if necessary
114
- gc! if @size > @max_size
113
+ gc! if size > @max_size
115
114
 
116
115
  value
117
116
  end
@@ -120,7 +119,7 @@ module Sprockets
120
119
  #
121
120
  # Returns String.
122
121
  def inspect
123
- "#<#{self.class} size=#{@size}/#{@max_size}>"
122
+ "#<#{self.class} size=#{size}/#{@max_size}>"
124
123
  end
125
124
 
126
125
  private
@@ -138,6 +137,10 @@ module Sprockets
138
137
  }.sort_by { |_, stat| stat.mtime.to_i }
139
138
  end
140
139
 
140
+ def size
141
+ @size ||= compute_size(find_caches)
142
+ end
143
+
141
144
  def compute_size(caches)
142
145
  caches.inject(0) { |sum, (_, stat)| sum + stat.size }
143
146
  end
@@ -55,7 +55,9 @@ module Sprockets
55
55
  if File.directory?(path)
56
56
  entries = Dir.entries(path, :encoding => Encoding.default_internal)
57
57
  entries.reject! { |entry|
58
- entry =~ /^\.|~$|^\#.*\#$/
58
+ entry.start_with?(".".freeze) ||
59
+ (entry.start_with?("#".freeze) && entry.end_with?("#".freeze)) ||
60
+ entry.end_with?("~".freeze)
59
61
  }
60
62
  entries.sort!
61
63
  else
@@ -14,10 +14,8 @@ module Sprockets
14
14
  @env = env
15
15
  uri = uri.to_s
16
16
  if uri.include?("://".freeze)
17
- uri_array = uri.split("://".freeze)
18
- @scheme = uri_array.shift
19
- @scheme << "://".freeze
20
- @path = uri_array.join("".freeze)
17
+ @scheme, _, @path = uri.partition("://".freeze)
18
+ @scheme << "://".freeze
21
19
  else
22
20
  @scheme = "".freeze
23
21
  @path = uri
@@ -74,16 +74,19 @@ module Sprockets
74
74
  def string_end_with_semicolon?(str)
75
75
  i = str.size - 1
76
76
  while i >= 0
77
- c = str[i]
77
+ c = str[i].ord
78
78
  i -= 1
79
- if c == "\n" || c == " " || c == "\t"
80
- next
81
- elsif c != ";"
82
- return false
83
- else
84
- return true
79
+
80
+ # Need to compare against the ordinals because the string can be UTF_8 or UTF_32LE encoded
81
+ # 0x0A == "\n"
82
+ # 0x20 == " "
83
+ # 0x09 == "\t"
84
+ # 0x3B == ";"
85
+ unless c == 0x0A || c == 0x20 || c == 0x09
86
+ return c === 0x3B
85
87
  end
86
88
  end
89
+
87
90
  true
88
91
  end
89
92
 
@@ -95,11 +98,21 @@ module Sprockets
95
98
  #
96
99
  # Returns buf String.
97
100
  def concat_javascript_sources(buf, source)
98
- if buf.bytesize > 0
99
- buf << ";" unless string_end_with_semicolon?(buf)
100
- buf << "\n" unless buf.end_with?("\n")
101
+ if source.bytesize > 0
102
+ buf << source
103
+
104
+ # If the source contains non-ASCII characters, indexing on it becomes O(N).
105
+ # This will lead to O(N^2) performance in string_end_with_semicolon?, so we should use 32 bit encoding to make sure indexing stays O(1)
106
+ source = source.encode(Encoding::UTF_32LE) unless source.ascii_only?
107
+
108
+ if !string_end_with_semicolon?(source)
109
+ buf << ";\n"
110
+ elsif source[source.size - 1].ord != 0x0A
111
+ buf << "\n"
112
+ end
101
113
  end
102
- buf << source
114
+
115
+ buf
103
116
  end
104
117
 
105
118
  # Internal: Prepends a leading "." to an extension if its missing.
@@ -1,3 +1,3 @@
1
1
  module Sprockets
2
- VERSION = "3.6.0"
2
+ VERSION = "3.6.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-06 00:00:00.000000000 Z
12
+ date: 2016-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack