def descr__new__(space, w_stringtype, w_object): # NB. the default value of w_object is really a *wrapped* empty string: # there is gateway magic at work from pypy.objspace.std.stringobject import W_StringObject w_obj = space.str(w_object) if space.is_w(w_stringtype, space.w_str): return w_obj # XXX might be reworked when space.str() typechecks value = space.str_w(w_obj) w_obj = space.allocate_instance(W_StringObject, w_stringtype) W_StringObject.__init__(w_obj, value) return w_obj
def descr__new__(space, w_stringtype, w_object=''): # NB. the default value of w_object is really a *wrapped* empty string: # there is gateway magic at work from pypy.objspace.std.stringobject import W_StringObject w_obj = space.str(w_object) if space.is_w(w_stringtype, space.w_str): return w_obj # XXX might be reworked when space.str() typechecks value = space.str_w(w_obj) if space.config.objspace.std.withrope: from pypy.objspace.std.ropeobject import rope, W_RopeObject w_obj = space.allocate_instance(W_RopeObject, w_stringtype) W_RopeObject.__init__(w_obj, rope.LiteralStringNode(value)) return w_obj else: w_obj = space.allocate_instance(W_StringObject, w_stringtype) W_StringObject.__init__(w_obj, value) return w_obj
def force(self): if self.w_str is None: s = self.builder.build() if self.length < len(s): s = s[:self.length] self.w_str = W_StringObject(s) return s else: return self.w_str._value
def wrapchar(space, c): from pypy.objspace.std.stringobject import W_StringObject from pypy.objspace.std.ropeobject import rope, W_RopeObject if space.config.objspace.std.withprebuiltchar: if space.config.objspace.std.withrope: return W_RopeObject.PREBUILT[ord(c)] return W_StringObject.PREBUILT[ord(c)] else: if space.config.objspace.std.withrope: return W_RopeObject(rope.LiteralStringNode(c)) return W_StringObject(c)
def wrapstr(space, s): from pypy.objspace.std.stringobject import W_StringObject if space.config.objspace.std.sharesmallstr: if space.config.objspace.std.withprebuiltchar: # share characters and empty string if len(s) <= 1: if len(s) == 0: return W_StringObject.EMPTY else: s = s[0] # annotator hint: a single char return wrapchar(space, s) else: # only share the empty string if len(s) == 0: return W_StringObject.EMPTY return W_StringObject(s)
def wrapchar(space, c): from pypy.objspace.std.stringobject import W_StringObject if space.config.objspace.std.withprebuiltchar and not jit.we_are_jitted(): return W_StringObject.PREBUILT[ord(c)] else: return W_StringObject(c)