Implement helper method to get char* buffer from Python objects
State: closed

- [x] closes N/A
- [x] tests added - `test_parsers_iso8601_leading_space`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

This is a follow-up PR for #25754 which adds a utility method for getting internal `char *` buffer from `unicode` or `bytes` Python object and switch at least some of usages to it.

Its advantages over what is built-in in Cython is saving at least one extra memory allocation (Cython internally calls Python C API that creates a new `char *` copy which is not needed for most `unicode` objects which are internally stored in `utf8` encoding), and it also obtains the length in one call.

cc @jbrockmendel 

Labels:
name: Internals
description: Related to non-user accessible pandas implementation

Comments:
Note for reviewers: errors in CI seem to be caused by #25875
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=h1) Report
> Merging [#25895](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/ac318d26cdbe3d10030f4863b84a06e938da9bba?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25895/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master   #25895   +/-   ##
=======================================
  Coverage   91.47%   91.47%           
=======================================
  Files         175      175           
  Lines       52863    52863           
=======================================
  Hits        48357    48357           
  Misses       4506     4506
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.04% <ø> (ø)` | :arrow_up: |
| #single | `41.8% <ø> (ø)` | :arrow_up: |


------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=footer). Last update [ac318d2...4d1916c](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=h1) Report
> Merging [#25895](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/882961df6025b800b899d351c243412e799accf4?src=pr&el=desc) will **increase** coverage by `0.23%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25895/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #25895      +/-   ##
==========================================
+ Coverage   91.53%   91.77%   +0.23%     
==========================================
  Files         175      175              
  Lines       52808    52606     -202     
==========================================
- Hits        48338    48277      -61     
+ Misses       4470     4329     -141
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.32% <ø> (+0.22%)` | :arrow_up: |
| #single | `41.9% <ø> (+0.07%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/compat/pickle\_compat.py](https://codecov.io/gh/pandas-dev/pandas/pull/25895/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9waWNrbGVfY29tcGF0LnB5) | `69.51% <0%> (-6.1%)` | :arrow_down: |
| [pandas/plotting/\_compat.py](https://codecov.io/gh/pandas-dev/pandas/pull/25895/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb21wYXQucHk=) | `83.33% <0%> (-3.34%)` | :arrow_down: |
| [pandas/compat/numpy/\_\_init\_\_.py](https://codecov.io/gh/pandas-dev/pandas/pull/25895/diff?src=pr&el=tree#diff-cGFuZGFzL2NvbXBhdC9udW1weS9fX2luaXRfXy5weQ==) | `93.1% <0%> (-0.23%)` | :arrow_down: |
| [pandas/io/sas/sas\_xport.py](https://codecov.io/gh/pandas-dev/pandas/pull/25895/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfeHBvcnQucHk=) | `90.09% <0%> (-0.05%)` | :arrow_down: |
| [pandas/io/packers.py](https://codecov.io/gh/pandas-dev/pandas/pull/25895/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhY2tlcnMucHk=) | `88.08% <0%> (-0.04%)` | :arrow_down: |
| [pandas/core/groupby/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/25895/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9nZW5lcmljLnB5) | `87.03% <0%> (-0.02%)` | :arrow_down: |
| [pandas/io/formats/csvs.py](https://codecov.io/gh/pandas-dev/pandas/pull/25895/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvY3N2cy5weQ==) | `98.2% <0%> (-0.02%)` | :arrow_down: |
| [pandas/core/arrays/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/25895/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lcy5weQ==) | `97.79% <0%> (-0.01%)` | :arrow_down: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/25895/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `97.99% <0%> (ø)` | :arrow_up: |
| [pandas/core/arrays/sparse.py](https://codecov.io/gh/pandas-dev/pandas/pull/25895/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3NwYXJzZS5weQ==) | `92.17% <0%> (ø)` | :arrow_up: |
| ... and [20 more](https://codecov.io/gh/pandas-dev/pandas/pull/25895/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=footer). Last update [882961d...f5f8e29](https://codecov.io/gh/pandas-dev/pandas/pull/25895?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Fun fact - it speeds up iso8601 parsing noticeably:

`asv continuous -f 1.05 882961df 1db613e6 -e -b timeseries.ToDatetimeISO8601 -a sample_time=1 -a warmup_time=1`

before|after|ratio|test name
-|-|-|-
[882961df]|[1db613e6]||
**master**|**get_string_data_pr**||
2.78±0.02ms|2.44±0.02ms|0.87|timeseries.ToDatetimeISO8601.time_iso8601_nosep
2.85±0.03ms|2.47±0.03ms|0.87|timeseries.ToDatetimeISO8601.time_iso8601_format
2.81±0.01ms|2.43±0.01ms|0.87|timeseries.ToDatetimeISO8601.time_iso8601_format_no_sep
2.84±0.03ms|2.44±0.03ms|0.86|timeseries.ToDatetimeISO8601.time_iso8601
lgtm. @jbrockmendel ?
lgtm. @jbrockmendel merge when ready.
Thanks @vnlitvin