Created
August 19, 2011 07:24
-
-
Save Neppord/1156257 to your computer and use it in GitHub Desktop.
Extendable strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#I dont have the knowledge to write this but i have the intrest in makeing it writen | |
#This is in no way complainat with the code of the pypy project and is just a sketch. | |
class Backend_string(W_object): | |
_imutable_fields_ = ["_value"] | |
def __init__(w_self, value): | |
w_self._value = value | |
def extend(w_self, w_other_real_string): | |
magic_extend_function(w_self._value, w_other_real_string.unwrap(None)) | |
class Real_string(W_object): | |
__imutable_fields_ = ["_back", "_len"] | |
def __init__(w_self, back, len): | |
w_self._back = back | |
w_self._len = len | |
def unwrap(w_self, space): | |
return w_self._back._value[:w_self._len] | |
def extend(w_self, w_other) | |
if w_self._len == len(w_self._back._value): | |
w_self._back.extend(w_other) | |
return Real_string(w_self._back, self._len + other._len) | |
else: | |
return Real_striing(Backend_string(w_self.unwrap(None) + w_other.unwrap(None)), self._len + other._len) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment