hashids 1.0.3 → 1.0.4

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +4 -0
  4. data/lib/hashids.rb +6 -9
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7838e770d8464e2dee709af97762ffe81aa169a6
4
- data.tar.gz: 9d6d15ad2f68c4a00d000f752ad47d45fa5ec4df
3
+ metadata.gz: bcf921c95958fac763731852a7bada447d74e30f
4
+ data.tar.gz: 6f6c71145d00140152c127e0978c28966fc30fe1
5
5
  SHA512:
6
- metadata.gz: 87ddcc37962df16da3cd708207ed69b2ff7f08d97fea78b7ad9a3b936f94ecfbb7486efbfcea8cf4fbcb9392256c151cdeef745ffe6ce2553dfb325eb4544d46
7
- data.tar.gz: 8556ae0a406ac8179e401d0023ded1a78577ce8d27ef4e1ae05c899d1b067009edce64fa5eba4731585f63422235ee88f5f68a9c646d582940fdf1d37049f6d5
6
+ metadata.gz: 6170e1679f92a5590f4a64c9350dd64bbca1518725726ef0340bd375c6c5f71779bf80b7dfd043e78b3c70ee00075376fcab13e57645ef36e45ec48efb9da154
7
+ data.tar.gz: b3baeb0247049a60da810b66206f44018923b248cf511451239053a0ec8f1c35d39e9ff0e71f5eb6c57ea0d6cd1ff1bccbab6e3806d0bbe9c9b2e2c2f720d602
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2016 Peter Hellberg
1
+ Copyright (c) 2013-2017 Peter Hellberg
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -208,6 +208,10 @@ hex_str = hashids.decode_hex("kRNrpKlJ")
208
208
 
209
209
  ## Changelog
210
210
 
211
+ **1.0.4**
212
+
213
+ - Improved encode/decode performance
214
+
211
215
  **1.0.3**
212
216
 
213
217
  - Support for Ruby 2.4.0
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class Hashids
4
- VERSION = "1.0.3"
4
+ VERSION = "1.0.4"
5
5
 
6
6
  MIN_ALPHABET_LENGTH = 16
7
7
  SEP_DIV = 3.5
@@ -142,24 +142,21 @@ class Hashids
142
142
 
143
143
  def consistent_shuffle(alphabet, salt)
144
144
  return alphabet if salt.nil? || salt.empty?
145
-
146
145
  v = 0
147
146
  p = 0
148
-
147
+ chars = alphabet.chars.to_a
148
+ slen = salt.length
149
149
  (alphabet.length-1).downto(1) do |i|
150
- v = v % salt.length
150
+ v = v % slen
151
151
  p += n = salt[v].ord
152
152
  j = (n + v + p) % i
153
153
 
154
- tmp_char = alphabet[j]
155
-
156
- alphabet = alphabet[0, j] + alphabet[i] + alphabet[j + 1..-1]
157
- alphabet = alphabet[0, i] + tmp_char + alphabet[i + 1..-1]
154
+ chars[i], chars[j] = chars[j], chars[i]
158
155
 
159
156
  v += 1
160
157
  end
161
158
 
162
- alphabet
159
+ chars.join
163
160
  end
164
161
 
165
162
  def hash(input, alphabet)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashids
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Hellberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-16 00:00:00.000000000 Z
11
+ date: 2017-08-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Use hashids when you do not want to expose your database ids to the user.
14
14
  email: