@@ -18,71 +18,54 @@ def initialize(option = nil)
18
18
self . identical = Concurrent ::Hash . new
19
19
self . masses = Concurrent ::Hash . new
20
20
end
21
-
22
- ##
23
- # Calculate the structural hash for this sexp. Cached, so don't
24
- # modify the sexp afterwards and expect it to be correct.
25
-
26
- if ENV [ "PURE_HASH" ]
27
- def structural_hash
28
- @structural_hash ||= pure_ruby_hash
29
- end
30
- else
31
- def structural_hash
32
- @structural_hash ||= Digest ::MD5 . hexdigest ( structure . to_s )
33
- end
34
- end
35
21
end
36
22
37
- # TODO: move this to flay proper... it's benchmarking faster
38
- class Sexp # straight from flay-persistent
39
- names = %w[ alias and arglist args array attrasgn attrset back_ref
40
- begin block block_pass break call case cdecl class colon2
41
- colon3 const cvar cvasgn cvdecl defined defn defs dot2
42
- dot3 dregx dregx_once dstr dsym dxstr ensure evstr false
43
- flip2 flip3 for gasgn gvar hash iasgn if iter ivar lasgn
44
- lit lvar masgn match match2 match3 module next nil not
45
- nth_ref op_asgn op_asgn1 op_asgn2 op_asgn_and op_asgn_or or
46
- postexe redo resbody rescue retry return sclass self
47
- splat str super svalue to_ary true undef until valias
48
- when while xstr yield zsuper kwarg kwsplat safe_call ]
49
-
50
- ##
51
- # All ruby_parser nodes in an index hash. Used by jenkins algorithm.
52
-
53
- NODE_NAMES = Hash [ names . each_with_index . map { |n , i | [ n . to_sym , i ] } ]
54
-
55
- NODE_NAMES . default_proc = lambda { |h , k |
56
- $stderr. puts "ERROR: couldn't find node type #{ k } in Sexp::NODE_NAMES."
57
- h [ k ] = NODE_NAMES . size
58
- }
59
-
60
- MAX_INT32 = 2 **32 - 1 # :nodoc:
61
-
62
- def pure_ruby_hash # :nodoc: see above
63
- hash = 0
64
-
65
- n = NODE_NAMES . fetch first
66
-
67
- raise "Bad lookup: #{ first } in #{ sexp . inspect } " unless n
68
-
69
- hash += n & MAX_INT32
70
- hash += hash << 10 & MAX_INT32
71
- hash ^= hash >> 6 & MAX_INT32
72
-
73
- each do |o |
74
- next unless o . is_a? Sexp
75
- hash = hash + o . pure_ruby_hash & MAX_INT32
76
- hash = ( hash + ( hash << 10 ) ) & MAX_INT32
77
- hash = ( hash ^ ( hash >> 6 ) ) & MAX_INT32
78
- end
79
-
80
- hash = ( hash + ( hash << 3 ) ) & MAX_INT32
81
- hash = ( hash ^ ( hash >> 11 ) ) & MAX_INT32
82
- hash = ( hash + ( hash << 15 ) ) & MAX_INT32
83
-
84
- hash
85
- end
23
+ new_nodes = [
24
+ :And , :ArrayExpression , :ArrowFunctionExpression ,
25
+ :Assign , :AssignmentExpression , :AssignmentPattern ,
26
+ :Attribute , :BinaryExpression , :BlockStatement , :BoolOp ,
27
+ :BooleanLiteral , :Break , :BreakStatement , :Call ,
28
+ :CallExpression , :CatchClause , :ClassBody ,
29
+ :ClassDeclaration , :ClassMethod , :Compare ,
30
+ :ConditionalExpression , :Continue , :ContinueStatement ,
31
+ :Dict , :Directive , :DirectiveLiteral , :DirectiveLiteral ,
32
+ :DoWhileStatement , :EmptyStatement , :Eq , :ExceptHandler ,
33
+ :ExportDefaultDeclaration , :ExportNamedDeclaration ,
34
+ :ExportSpecifier , :Expr , :ExpressionStatement , :For ,
35
+ :ForInStatement , :ForStatement , :FunctionDeclaration ,
36
+ :FunctionDef , :FunctionExpression , :Gt , :Identifier , :If ,
37
+ :IfExp , :IfStatement , :Import , :ImportDeclaration ,
38
+ :ImportDefaultSpecifier , :ImportFrom , :ImportSpecifier ,
39
+ :Index , :LabeledStatement , :LogicalExpression , :LtE ,
40
+ :MemberExpression , :Name , :NewExpression , :NotIn ,
41
+ :NullLiteral , :Num , :NumericLiteral , :ObjectExpression ,
42
+ :ObjectMethod , :ObjectPattern , :ObjectProperty , :Or ,
43
+ :Print , :RegExpLiteral , :ReturnStatement ,
44
+ :SequenceExpression , :Slice , :Str , :StringLiteral ,
45
+ :Subscript , :Super , :SwitchCase , :SwitchStatement ,
46
+ :TaggedTemplateExpression , :TemplateElement ,
47
+ :TemplateLiteral , :ThisExpression , :ThrowStatement ,
48
+ :TryExcept , :TryStatement , :Tuple , :UnaryExpression ,
49
+ :UpdateExpression , :VariableDeclaration ,
50
+ :VariableDeclarator , :WhileStatement , :Yield , :alternate ,
51
+ :argument , :arguments , :array_dim_fetch , :assign ,
52
+ :assign_op_minus , :binary_op_bitwise_and ,
53
+ :binary_op_bitwise_or , :binary_op_concat ,
54
+ :binary_op_shift_right , :binary_op_smaller_or_equal ,
55
+ :body , :callee , :cases , :comparators , :consequent ,
56
+ :declaration , :declarations , :directives , :elements ,
57
+ :elts , :exp , :expression , :expressions , :extra ,
58
+ :finalizer , :foreach , :func_call , :function , :id , :init ,
59
+ :init , :key , :keyword , :left , :list , :lnumber , :name ,
60
+ :object , :param , :params , :properties , :property ,
61
+ :quasis , :right , :specifiers , :string , :superClass ,
62
+ :target , :test , :update , :value , :values ,
63
+ :variable
64
+ ]
65
+
66
+ # Add known javascript and php nodes to the hash registry.
67
+ new_nodes . each do |name |
68
+ Sexp ::NODE_NAMES [ name ] = Sexp ::NODE_NAMES . size
86
69
end
87
70
88
71
class Sexp
@@ -108,17 +91,3 @@ def flatter
108
91
end
109
92
end
110
93
end
111
-
112
- class Sexp # TODO: push this back to flay
113
- alias old_mass mass
114
-
115
- def mass
116
- @mass ||= inject ( 1 ) do |t , s |
117
- if s . is_a? ( Sexp )
118
- t + s . mass
119
- else
120
- t
121
- end
122
- end
123
- end
124
- end
0 commit comments