summaryrefslogtreecommitdiffstatshomepage
path: root/py/objstr.c
Commit message (Collapse)AuthorAge
* 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
|
* py: Rename MP_BOOL() to mp_obj_new_bool() for consistency in naming.Paul Sokolovsky2015-10-11
|
* py: Eliminate some cases which trigger unused parameter warnings.Damien George2015-09-04
|
* py/objstr: Check for keyword args before checking for no posn args.Damien George2015-09-04
| | | | Otherwise something like bytes(abc=123) will succeed.
* py/objstr: For str.endswith(s, start) raise NotImpl instead of assert.Damien George2015-09-04
|
* py: Use mp_not_implemented consistently for not implemented features.Damien George2015-09-03
|
* py/objstr: Simplify printing of bytes objects when unicode enabled.Damien George2015-09-03
|
* py: Inline single use of mp_obj_str_get_len in mp_obj_len_maybe.Damien George2015-09-03
| | | | | | Gets rid of redundant double check for string type. Also remove obsolete declaration of mp_obj_str_get_hash.
* py/objstr: Make str.rsplit(None,n) raise NotImpl instead of assert(0).Damien George2015-09-01
|
* py/objstr: Simplify error handling for bad conversion specifier.Damien George2015-08-30
|
* py/objstr: Fix error reporting for unexpected end of modulo format str.Damien George2015-08-29
|
* py/objstr: Fix error type for badly formatted format specifier.Damien George2015-08-29
| | | | Was KeyError, should be ValueError.
* py/objstr: Make string formatting 8-bit clean.Damien George2015-08-29
|
* py: Prevent many extra vstr allocations.Dave Hylands2015-07-06
| | | | | | | | | | | | | | | | | | | | | | | | | I checked the entire codebase, and every place that vstr_init_len was called, there was a call to mp_obj_new_str_from_vstr after it. mp_obj_new_str_from_vstr always tries to reallocate a new buffer 1 byte larger than the original to store the terminating null character. In many cases, if we allocated the initial buffer to be 1 byte longer, we can prevent this extra allocation, and just reuse the originally allocated buffer. Asking to read 256 bytes and only getting 100 will still cause the extra allocation, but if you ask to read 256 and get 256 then the extra allocation will be optimized away. Yes - the reallocation is optimized in the heap to try and reuse the buffer if it can, but it takes quite a few cycles to figure this out. Note by Damien: vstr_init_len should now be considered as a string-init convenience function and used only when creating null-terminated objects.
* objstr: Add note that replace() is nicely optimized.Paul Sokolovsky2015-06-26
| | | | | Doesn't allocate memory and returns original string if no replacements are to be made.
* py: Remove unnecessary extra handling of padding of nan/inf.Damien George2015-05-28
| | | | | | | C's printf will pad nan/inf differently to CPython. Our implementation originally conformed to C, now it conforms to CPython's way. Tests for this are also added in this patch.
* py: Clean up declarations of str type/funcs that are also in unicode.Damien George2015-05-17
| | | | | Background: trying to make an amalgamation of all the code gave some errors with redefined types and inconsistent use of static.
* py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function.Damien George2015-05-12
| | | | | | | | | | | | | | Hashing is now done using mp_unary_op function with MP_UNARY_OP_HASH as the operator argument. Hashing for int, str and bytes still go via fast-path in mp_unary_op since they are the most common objects which need to be hashed. This lead to quite a bit of code cleanup, and should be more efficient if anything. It saves 176 bytes code space on Thumb2, and 360 bytes on x86. The only loss is that the error message "unhashable type" is now the more generic "unsupported type for __hash__".
* py: Add optional code to check bytes constructor values are in range.Damien George2015-04-23
| | | | | | Compiled in only if MICROPY_CPYTHON_COMPAT is set. Addresses issue #1093.
* py: Overhaul and simplify printf/pfenv mechanism.Damien George2015-04-16
| | | | | | | | | | | | | | | | | | | | | | Previous to this patch the printing mechanism was a bit of a tangled mess. This patch attempts to consolidate printing into one interface. All (non-debug) printing now uses the mp_print* family of functions, mainly mp_printf. All these functions take an mp_print_t structure as their first argument, and this structure defines the printing backend through the "print_strn" function of said structure. Printing from the uPy core can reach the platform-defined print code via two paths: either through mp_sys_stdout_obj (defined pert port) in conjunction with mp_stream_write; or through the mp_plat_print structure which uses the MP_PLAT_PRINT_STRN macro to define how string are printed on the platform. The former is only used when MICROPY_PY_IO is defined. With this new scheme printing is generally more efficient (less layers to go through, less arguments to pass), and, given an mp_print_t* structure, one can call mp_print_str for efficiency instead of mp_printf("%s", ...). Code size is also reduced by around 200 bytes on Thumb2 archs.
* objstr: split(None): Fix whitespace properly.Paul Sokolovsky2015-04-12
|
* py: Some trivial cosmetic changes, for code style consistency.Damien George2015-04-04
|
* objstr: Fix bugs introduced by inability to have shadow variables.Paul Sokolovsky2015-04-04
| | | | Warnings lead to programming errors - as expected.
* objstr: Avoid variable shadowing.Paul Sokolovsky2015-04-04
|