Class: Integer
- Defined in:
- lib/amp/dependencies/amp_support/ruby_amp_support.rb,
lib/amp/support/support.rb
Overview
Ruby versions of slow functions we’ve implemented in C
Instance Method Summary collapse
-
#byte_swap_64 ⇒ Integer
Used for byte-swapping a 64-bit double long.
-
#bytes ⇒ Object
(also: #byte, #b)
methods for converting between file sizes.
-
#gigabytes ⇒ Object
(also: #gigabyte, #gb)
methods for converting between file sizes.
-
#kilobytes ⇒ Object
(also: #kilobyte, #kb)
methods for converting between file sizes.
-
#megabytes ⇒ Object
(also: #megabyte, #mb)
methods for converting between file sizes.
-
#to_dirstate_symbol ⇒ Object
Converts an ascii value to a dirstate status symbol.
-
#to_signed_16 ⇒ Integer
Returns the number as if it were a signed 16-bit integer.
-
#to_signed_32 ⇒ Integer
Returns the number as if it were a signed 32-bit integer.
Instance Method Details
#byte_swap_64 ⇒ Integer
Used for byte-swapping a 64-bit double long. Unfortuantely, this will invoke bignum logic, which is ridiculously slow. That’s why we have a C extension.
If the system is little endian, we work some magic. If the system is big endian, we just return self.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/amp/dependencies/amp_support/ruby_amp_support.rb', line 15 def byte_swap_64 if Amp::Support::SYSTEM[:endian] == :little ((self >> 56)) | ((self & 0x00FF000000000000) >> 40) | ((self & 0x0000FF0000000000) >> 24) | ((self & 0x000000FF00000000) >> 8 ) | ((self & 0x00000000FF000000) << 8 ) | ((self & 0x0000000000FF0000) << 24) | ((self & 0x000000000000FF00) << 40) | ((self & 0x00000000000000FF) << 56) else self end end |
#bytes ⇒ Object Also known as: byte, b
methods for converting between file sizes
648 649 650 |
# File 'lib/amp/support/support.rb', line 648 def bytes self end |
#gigabytes ⇒ Object Also known as: gigabyte, gb
methods for converting between file sizes
669 670 671 |
# File 'lib/amp/support/support.rb', line 669 def gigabytes 1024 * megabytes end |
#kilobytes ⇒ Object Also known as: kilobyte, kb
methods for converting between file sizes
655 656 657 |
# File 'lib/amp/support/support.rb', line 655 def kilobytes 1024 * bytes end |
#megabytes ⇒ Object Also known as: megabyte, mb
methods for converting between file sizes
662 663 664 |
# File 'lib/amp/support/support.rb', line 662 def megabytes 1024 * kilobytes end |
#to_dirstate_symbol ⇒ Object
Converts an ascii value to a dirstate status symbol. Converts a fixnum, which is an ascii value, to a symbol representing a dirstate entry’s status. Since we don’t like passing around ‘n’, and want to pass around :normal, we need a fast lookup for ascii value -> symbol. The price we pay.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/amp/dependencies/amp_support/ruby_amp_support.rb', line 53 def to_dirstate_symbol case self when 110 # "n".ord :normal when 63 # "?".ord :untracked when 97 # "a".ord :added when 109 # "m".ord :merged when 114 # "r".ord :removed else raise "No known hg value for #{self}" end end |
#to_signed_16 ⇒ Integer
Returns the number as if it were a signed 16-bit integer. Since unpack() always returns unsigned integers, we have to sign them here.
31 32 33 34 |
# File 'lib/amp/dependencies/amp_support/ruby_amp_support.rb', line 31 def to_signed_16 return self if self < 32785 return self - 65536 end |
#to_signed_32 ⇒ Integer
Returns the number as if it were a signed 32-bit integer. Since unpack() always returns unsigned integers, we have to sign them here.
41 42 43 44 |
# File 'lib/amp/dependencies/amp_support/ruby_amp_support.rb', line 41 def to_signed_32 return self if self < 2147483648 return self - 4294967296 end |