1.1 --- a/lib/__builtins__/str.py Sun Feb 12 23:24:42 2017 +0100
1.2 +++ b/lib/__builtins__/str.py Mon Feb 13 18:54:59 2017 +0100
1.3 @@ -22,8 +22,8 @@
1.4 from __builtins__.operator import _negate
1.5 from __builtins__.sequence import hashable, itemaccess
1.6 from __builtins__.types import check_int
1.7 -from native import str_add, str_lt, str_gt, str_eq, str_len, str_ord, \
1.8 - str_nonempty, str_substr
1.9 +from native import int_new, str_add, str_lt, str_gt, str_eq, str_ord, \
1.10 + str_substr
1.11
1.12 WHITESPACE = (" ", "\f", "\n", "\r", "\t")
1.13
1.14 @@ -39,26 +39,25 @@
1.15 # literals or converted using routines defined for other types, no form
1.16 # of actual initialisation is performed here.
1.17
1.18 + # Note the __key__ member. This is also initialised statically. Where
1.19 + # a string is the same as an attribute name, the __key__ member contains
1.20 + # attribute position and code details.
1.21 +
1.22 # NOTE: Cannot perform "other and other.__data__ or None" since the
1.23 # NOTE: __data__ attribute is not a normal attribute.
1.24
1.25 if other:
1.26 self.__data__ = other.__data__
1.27 + self.__key__ = other.__key__
1.28 + self.__size__ = other.__size__
1.29 else:
1.30 self.__data__ = None
1.31 -
1.32 - # Note the __key__ member. This is also initialised statically. Where
1.33 - # a string is the same as an attribute name, the __key__ member contains
1.34 - # attribute position and code details.
1.35 -
1.36 - if other:
1.37 - self.__key__ = other.__key__
1.38 - else:
1.39 self.__key__ = None
1.40 + self.__size__ = None
1.41
1.42 # Internal methods.
1.43
1.44 - def _binary_op(self, op, other):
1.45 + def _binary_op(self, op, other, sizes=False):
1.46
1.47 "Perform 'op' on this object and 'other' if appropriate."
1.48
1.49 @@ -69,10 +68,12 @@
1.50
1.51 # Otherwise, perform the operation on the operands' data.
1.52
1.53 + elif sizes:
1.54 + return op(self.__data__, other.__data__, self.__size__, other.__size__)
1.55 else:
1.56 return op(self.__data__, other.__data__)
1.57
1.58 - def _binary_op_rev(self, op, other):
1.59 + def _binary_op_rev(self, op, other, sizes=False):
1.60
1.61 "Perform 'op' on 'other' and this object if appropriate."
1.62
1.63 @@ -83,6 +84,8 @@
1.64
1.65 # Otherwise, perform the operation on the operands' data.
1.66
1.67 + elif sizes:
1.68 + return op(other.__data__, self.__data__, other.__size__, self.__size__)
1.69 else:
1.70 return op(other.__data__, self.__data__)
1.71
1.72 @@ -154,7 +157,7 @@
1.73
1.74 "Return the number of bytes in this string."
1.75
1.76 - return str_len(self.__data__)
1.77 + return int_new(self.__size__)
1.78
1.79 # General type methods.
1.80
1.81 @@ -162,7 +165,7 @@
1.82
1.83 "Return whether the string provides any data."
1.84
1.85 - return str_nonempty(self.__data__)
1.86 + return int_new(self.__size__).__bool__()
1.87
1.88 def __contains__(self, value):
1.89
1.90 @@ -196,7 +199,7 @@
1.91
1.92 "Return a string combining this string with 'other'."
1.93
1.94 - return self._binary_op(str_add, other)
1.95 + return self._binary_op(str_add, other, True)
1.96
1.97 __add__ = __iadd__
1.98
1.99 @@ -204,7 +207,7 @@
1.100
1.101 "Return a string combining this string with 'other'."
1.102
1.103 - return self._binary_op_rev(str_add, other)
1.104 + return self._binary_op_rev(str_add, other, True)
1.105
1.106 def __mod__(self, other): pass
1.107 def __rmod__(self, other): pass