summaryrefslogtreecommitdiffstatshomepage
path: root/py/objstr.c
Commit message (Collapse)AuthorAge
* all: Use the name MicroPython consistently in commentsAlexander Steffen2017-07-31
| | | | | There were several different spellings of MicroPython present in comments, when there should be only one.
* py/objstr: Remove unnecessary "sign" variable in formatting code.Damien George2017-07-04
|
* py/objstr: Move uPy function wrappers to just after the C function.Damien George2017-07-02
| | | | This matches the coding/layout style of all the other objects.
* py/objstr: Allow to compile with obj-repr D, and unicode disabled.Damien George2017-06-08
|
* py/objstr: Catch case of negative "maxsplit" arg to str.rsplit().Damien George2017-06-02
| | | | | Negative values mean no limit on the number of splits so should delegate to the .split() method.
* various: Spelling fixesVille Skyttä2017-05-29
|
* py/objstr: Use MICROPY_FULL_CHECKS for range checking when constructing bytes.Paul Sokolovsky2017-04-02
| | | | | | | Split this setting from MICROPY_CPYTHON_COMPAT. The idea is to be able to keep MICROPY_CPYTHON_COMPAT disabled, but still pass more of regression testsuite. In particular, this fixes last failing test in basics/ for Zephyr port.
* py: Change mp_uint_t to size_t for mp_obj_str_get_data len arg.Damien George2017-03-29
|
* py: Convert mp_uint_t to size_t for tuple/list accessors.Damien George2017-03-29
| | | | | | | | | | | | | | | | | | | | This patch changes mp_uint_t to size_t for the len argument of the following public facing C functions: mp_obj_tuple_get mp_obj_list_get mp_obj_get_array These functions take a pointer to the len argument (to be filled in by the function) and callers of these functions should update their code so the type of len is changed to size_t. For ports that don't use nan-boxing there should be no change in generate code because the size of the type remains the same (word sized), and in a lot of cases there won't even be a compiler warning if the type remains as mp_uint_t. The reason for this change is to standardise on the use of size_t for variables that count memory (or memory related) sizes/lengths. It helps builds that use nan-boxing.
* py: Use size_t as len argument and return type of mp_get_index.Damien George2017-03-23
| | | | | These values are used to compute memory addresses and so size_t is the more appropriate type to use.
* py/objstr: Use better msg in bad implicit str/bytes conversion exceptionstijn2017-03-20
| | | | | | | | | | Instead of always reporting some object cannot be implicitly be converted to a 'str', even when it is a 'bytes' object, adjust the logic so that when trying to convert str to bytes it is shown like that. This will still report bad implicit conversion from e.g. 'int to bytes' as 'int to str' but it will not result in the confusing 'can't convert 'str' object to str implicitly' anymore for calls like b'somestring'.count('a').
* py/objstr: Fix eager optimisation of str/bytes addition.Damien George2017-03-16
| | | | The RHS can only be returned if it is the same type as the LHS.
* py: Use mp_obj_get_array where sequence may be a tuple or a list.Krzysztof Blazewicz2017-03-07
|
* py: Add iter_buf to getiter type method.Damien George2017-02-16
| | | | | | | | | | | | | | | Allows to iterate over the following without allocating on the heap: - tuple - list - string, bytes - bytearray, array - dict (not dict.keys, dict.values, dict.items) - set, frozenset Allows to call the following without heap memory: - all, any, min, max, sum TODO: still need to allocate stack memory in bytecode for iter_buf.
* py/objstr: Convert mp_uint_t to size_t (and use int) where appropriate.Damien George2017-02-16
|
* py/objstr: Convert some instances of mp_uint_t to size_t.Damien George2017-02-03
|
* py/objstr: Give correct behaviour when passing a dict to %-formatting.Damien George2017-02-03
| | | | | | This patch fixes two main things: - dicts can be printed directly using '%s' % dict - %-formatting should not crash when passed a non-dict to, eg, '%(foo)s'
* py/objstr: Optimize string concatenation with empty string.Paul Sokolovsky2017-01-27
| | | | | | | | | | | | | | In this, don't allocate copy, just return non-empty string. This helps with a standard pattern of buffering data in case of short reads: buf = b"" while ...: s = f.read(...) buf += s ... For a typical case when single read returns all data needed, there won't be extra allocation. This optimization helps uasyncio.
* py/objstr: Remove unreachable function used only for terse error msgs.Damien George2016-09-27
|
* py: If str/bytes hash is 0 then explicitly compute it.Damien George2016-09-02
|
* py/objstr: Use mp_raise_{Type,Value}Error instead of mp_raise_msg.Damien George2016-08-14
| | | | | This patch does further refactoring using the new mp_raise_TypeError and mp_raise_ValueError functions.
* py: Get rid of assert() in method argument checking functions.Paul Sokolovsky2016-08-12
| | | | | | Checks for number of args removes where guaranteed by function descriptor, self checking is replaced with mp_check_self(). In few cases, exception is raised instead of assert.
* py/runtime: Factor out exception raising helpers.Paul Sokolovsky2016-08-12
| | | | | | Introduce mp_raise_msg(), mp_raise_ValueError(), mp_raise_TypeError() instead of previous pattern nlr_raise(mp_obj_new_exception_msg(...)). Save few bytes on each call, which are many.
* py/objstr,objstrunicode: Fix inconistent #if indentation.Paul Sokolovsky2016-08-07
|
* py/objstr: Make .partition()/.rpartition() methods configurable.Paul Sokolovsky2016-08-07
| | | | Default is disabled, enabled for unix port. Saves 600 bytes on x86.
* py/objstr: Fix mix-signed comparison in str.center().Paul Sokolovsky2016-05-22
|
* py/objstr*: Properly ifdef str.center().Dave Hylands2016-05-22
|
* py/objstr: Implement str.center().Paul Sokolovsky2016-05-22
| | | | | | Disabled by default, enabled in unix port. Need for this method easily pops up when working with text UI/reporting, and coding workalike manually again and again counter-productive.
* py/objstr: Make dedicated splitlines function, supporting diff newlines.Damien George2016-05-13
| | | | | | | | It now supports \n, \r and \r\n as newline separators. Adds 56 bytes to stmhal and 80 bytes to unix x86-64. Fixes issue #1689.
* Revert "py/objstr: .format(): Avoid call to vstr_null_terminated_str()."Paul Sokolovsky2016-05-09
| | | | | | This reverts commit 6de8dbb4880e58c68a08205cb2b9c15940143439. The change was incorrect (correct change would require comparing with end pointer in each if statement in the block).
* py/objstr: .format(): Avoid call to vstr_null_terminated_str().Paul Sokolovsky2016-05-09
| | | | | By comparing with string end pointer instead of checking for NUL byte. Should alleviate reallocations and fragmentation a tiny bit.
* py/objstr: Binary type of str/bytes for buffer protocol is 'B'.Damien George2016-05-07
| | | | | | The type is an unsigned 8-bit value, since bytes objects are exactly that. And it's also sensible for unicode strings to return unsigned values when accessed in a byte-wise manner (CPython does not allow this).
* py/makeqstrdata: Add special case to handle \n qstr.Damien George2016-04-14
|
* py/objarray: Implement "in" operator for bytearray.Paul Sokolovsky2016-02-14
|
* py/objstr: Make mp_obj_str_format_helper static.Damien George2016-02-02
|
* py/objstr: For str.format, don't allocate on the heap for field name.Damien George2016-02-02
|
* py/objstr: For str.format, add nested/computed fields support.pohmelie2016-02-02
| | | | | | | Eg: '{:{}}'.format(123, '>20') @pohmelie was the original author of this patch, but @dpgeorge made significant changes to reduce code size and improve efficiency.
* py: Use new code pattern for parsing kw args with mp_arg_parse_all.Damien George2016-01-13
| | | | Makes code easier to read and more maintainable.
* py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.Damien George2016-01-11
| | | | | | | | The first argument to the type.make_new method is naturally a uPy type, and all uses of this argument cast it directly to a pointer to a type structure. So it makes sense to just have it a pointer to a type from the very beginning (and a const pointer at that). This patch makes such a change, and removes all unnecessary casting to/from mp_obj_t.
* py: Change type signature of builtin funs that take variable or kw args.Damien George2016-01-11
| | | | | With this patch the n_args parameter is changed type from mp_uint_t to size_t.
* py: Change type of .make_new and .call args: mp_uint_t becomes size_t.Damien George2016-01-11
| | | | | | | This patch changes the type signature of .make_new and .call object method slots to use size_t for n_args and n_kw (was mp_uint_t. Makes code more efficient when mp_uint_t is larger than a machine word. Doesn't affect ports when size_t and mp_uint_t have the same size.
* py/objstr: In str.format, handle case of no format spec for string arg.Damien George2016-01-04
| | | | | Handles, eg, "{:>20}".format("foo"), where there is no explicit spec for the type of the argument.
* py: Use polymorphic iterator type where possible to reduce code size.Damien George2016-01-03
| | | | | | | Only types whose iterator instances still fit in 4 machine words have been changed to use the polymorphic iterator. Reduces Thumb2 arch code size by 264 bytes.
* py/objstr: Applying % (format) operator to bytes should return bytes, not str.Paul Sokolovsky2015-12-20
|
* py/objstr: Make sure that b"%s" % b"foo" uses undecorated bytes value.Paul Sokolovsky2015-12-20
| | | | | I.e. the expected result for above is b"foo", whereas previously we got b"b'foo'".
* py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George2015-11-29
| | | | | | | | | This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
* py: Add MP_ROM_* macros and mp_rom_* types and use them.Damien George2015-11-29
|
* py: Change qstr_* functions to use size_t as the type for str len arg.Damien George2015-11-29
|
* py: With obj repr "C", change raw str accessor from macro to function.Damien George2015-10-20
| | | | | | This saves around 1000 bytes (Thumb2 arch) because in repr "C" it is costly to check and extract a qstr. So making such check/extract a function instead of a macro saves lots of code space.
* py: Add mp_obj_is_float function (macro) and use it where appropriate.Damien George2015-10-20
|