MCPcopy Create free account
hub / github.com/ampproject/amphtml / InternString

Method InternString

validator/validator_gen_js.py:132–146  ·  view source on GitHub ↗

Interns strings to eliminate duplicates and to refer to them as numbers. Args: a_string: the string to be interned Returns: The string id, a negative number -1 to -MAXINT.

(self, a_string)

Source from the content-addressed store, hash-verified

130 self.string_id_by_interned_string_ = {}
131
132 def InternString(self, a_string):
133 """Interns strings to eliminate duplicates and to refer to them as numbers.
134
135 Args:
136 a_string: the string to be interned
137 Returns:
138 The string id, a negative number -1 to -MAXINT.
139 """
140 string_id = self.string_id_by_interned_string_.get(a_string, 0)
141 if string_id != 0:
142 return string_id
143 self.interned_strings_.append(a_string)
144 string_id = -len(self.interned_strings_)
145 self.string_id_by_interned_string_[a_string] = string_id
146 return string_id
147
148 def InternedStrings(self):
149 """The interned strings which will be emitted into validator-generated.js.

Callers 3

InternOrReferenceFunction · 0.80
PrintObjectFunction · 0.80

Calls 2

getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected