summaryrefslogtreecommitdiffstatshomepage
path: root/py/objstr.c
Commit message (Collapse)AuthorAge
* 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
|
* objstr: Add .splitlines() method.Paul Sokolovsky2015-04-04
| | | | | | | | | splitlines() occurs ~179 times in CPython3 standard library, so was deemed worthy to implement. The method has subtle semantic differences from just .split("\n"). It is also defined as working for any end-of-line combination, but this is currently not implemented - it works only with LF line-endings (which should be OK for text strings on any platforms, but not OK for bytes).
* objstr: Expose mp_obj_str_split() for reuse in other modules.Paul Sokolovsky2015-03-23
|
* py: Remove unnecessary and unused sgn argument from pfenv_print_mp_int.Damien George2015-03-14
|
* objstr: Fix bytes creation from array of long ints.Paul Sokolovsky2015-02-09
|
* py: Change vstr_null_terminate -> vstr_null_terminated_str, returns str.Damien George2015-01-29
|
* py: Change vstr so that it doesn't null terminate buffer by default.Damien George2015-01-28
| | | | | | | | | This cleans up vstr so that it's a pure "variable buffer", and the user can decide whether they need to add a terminating null byte. In most places where vstr is used, the vstr did not need to be null terminated and so this patch saves code size, a tiny bit of RAM, and makes vstr usage more efficient. When null termination is needed it must be done explicitly using vstr_null_terminate.
* py: bytes(): Make sure we add values as bytes, not as chars.Paul Sokolovsky2015-01-28
|
* py: Remove duplicated mp_obj_str_make_new function from objstrunicode.c.Damien George2015-01-28
|
* objstr: Remove code duplication and unbreak Windows build.Paul Sokolovsky2015-01-23
| | | | | | | | There was really weird warning (promoted to error) when building Windows port. Exact cause is still unknown, but it uncovered another issue: 8-bit and unicode str_make_new implementations should be mutually exclusive, and not built at the same time. What we had is that bytes_decode() pulled 8-bit str_make_new() even for unicode build.
* objstr*: Use separate names for locals_dict of 8-bit and unicode str's.Paul Sokolovsky2015-01-23
| | | | To somewhat unbreak -DSTATIC="" compile.
* py: Add comments for vstr_init and mp_obj_new_str.Damien George2015-01-21
|
* py: Remove mp_obj_str_builder and use vstr instead.Damien George2015-01-21
| | | | | | | | | | | | With this patch str/bytes construction is streamlined. Always use a vstr to build a str/bytes object. If the size is known beforehand then use vstr_init_len to allocate only required memory. Otherwise use vstr_init and the vstr will grow as needed. Then use mp_obj_new_str_from_vstr to create a str/bytes object using the vstr memory. Saves code ROM: 68 bytes on stmhal, 108 bytes on bare-arm, and 336 bytes on unix x64.
* py: Add mp_obj_new_str_from_vstr, and use it where relevant.Damien George2015-01-21
| | | | | | | | This patch allows to reuse vstr memory when creating str/bytes object. This improves memory usage. Also saves code ROM: 128 bytes on stmhal, 92 bytes on bare-arm, and 88 bytes on unix x64.
* py, unix: Allow to compile with -Wunused-parameter.Damien George2015-01-20
| | | | See issue #699.
* py, unix, stmhal: Allow to compile with -Wshadow.Damien George2015-01-20
| | | | See issue #699.
* py, unix: Allow to compile with -Wsign-compare.Damien George2015-01-16
| | | | See issue #699.
* py, unix: Allow to compile with -Wdouble-promotion.Damien George2015-01-12
| | | | Ref issue #699.
* py: Remove unnecessary BINARY_OP_EQUAL code that just checks pointers.Damien George2015-01-11
| | | | | | | Previous patch c38dc3ccc76d1a9bf867704f43ea5d15da3fea7b allowed any object to be compared with any other, using pointer comparison for a fallback. As such, existing code which checked for this case is no longer needed.
* objstr: Common subexpression elimination for vstr_str(field_name).Paul Sokolovsky2015-01-04
|
* objstr: Implement kwargs support for str.format().Paul Sokolovsky2015-01-04
|
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* objstr: Fix %d-formatting of floats.Paul Sokolovsky2014-12-31
|
* py: Make bytes objs work with more str methods; add tests.Damien George2014-12-24
|
* py: Use str_to_int function in more places to reduce code size.Damien George2014-12-21
|
* py: Fix function type: () -> (void).Damien George2014-12-10
|
* py: Allow bytes/bytearray/array to be init'd by buffer protocol objects.Damien George2014-12-04
| | | | | | | Behaviour of array initialisation is subtly different for bytes, bytearray and array.array when argument has buffer protocol. This patch gets us CPython conformant (except we allow initialisation of array.array by buffer with length not a multiple of typecode).
* py: #if guard str_make_new when not needed.Damien George2014-11-27
|
* py: Use shorter, static error msgs when ERROR_REPORTING_TERSE enabled.Damien George2014-11-06
| | | | | | | | Going from MICROPY_ERROR_REPORTING_NORMAL to MICROPY_ERROR_REPORTING_TERSE now saves 2020 bytes ROM for ARM Thumb2, and 2200 bytes ROM for 32-bit x86. This is about a 2.5% code size reduction for bare-arm.