Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)