rust/library/std/src/sys_common
Eduardo Sánchez Muñoz 23637e20cd libcore: assume the input of next_code_point and next_code_point_reverse is UTF-8-like
The functions are now `unsafe` and they use `Option::unwrap_unchecked` instead of `unwrap_or_0`

`unwrap_or_0` was added in 42357d772b. I guess `unwrap_unchecked` was not available back then.

Given this example:

```rust
pub fn first_char(s: &str) -> Option<char> {
    s.chars().next()
}
```

Previously, the following assembly was produced:

```asm
_ZN7example10first_char17ha056ddea6bafad1cE:
	.cfi_startproc
	test	rsi, rsi
	je	.LBB0_1
	movzx	edx, byte ptr [rdi]
	test	dl, dl
	js	.LBB0_3
	mov	eax, edx
	ret
.LBB0_1:
	mov	eax, 1114112
	ret
.LBB0_3:
	lea	r8, [rdi + rsi]
	xor	eax, eax
	mov	r9, r8
	cmp	rsi, 1
	je	.LBB0_5
	movzx	eax, byte ptr [rdi + 1]
	add	rdi, 2
	and	eax, 63
	mov	r9, rdi
.LBB0_5:
	mov	ecx, edx
	and	ecx, 31
	cmp	dl, -33
	jbe	.LBB0_6
	cmp	r9, r8
	je	.LBB0_9
	movzx	esi, byte ptr [r9]
	add	r9, 1
	and	esi, 63
	shl	eax, 6
	or	eax, esi
	cmp	dl, -16
	jb	.LBB0_12
.LBB0_13:
	cmp	r9, r8
	je	.LBB0_14
	movzx	edx, byte ptr [r9]
	and	edx, 63
	jmp	.LBB0_16
.LBB0_6:
	shl	ecx, 6
	or	eax, ecx
	ret
.LBB0_9:
	xor	esi, esi
	mov	r9, r8
	shl	eax, 6
	or	eax, esi
	cmp	dl, -16
	jae	.LBB0_13
.LBB0_12:
	shl	ecx, 12
	or	eax, ecx
	ret
.LBB0_14:
	xor	edx, edx
.LBB0_16:
	and	ecx, 7
	shl	ecx, 18
	shl	eax, 6
	or	eax, ecx
	or	eax, edx
	ret
```

After this change, the assembly is reduced to:

```asm
_ZN7example10first_char17h4318683472f884ccE:
	.cfi_startproc
	test	rsi, rsi
	je	.LBB0_1
	movzx	ecx, byte ptr [rdi]
	test	cl, cl
	js	.LBB0_3
	mov	eax, ecx
	ret
.LBB0_1:
	mov	eax, 1114112
	ret
.LBB0_3:
	mov	eax, ecx
	and	eax, 31
	movzx	esi, byte ptr [rdi + 1]
	and	esi, 63
	cmp	cl, -33
	jbe	.LBB0_4
	movzx	edx, byte ptr [rdi + 2]
	shl	esi, 6
	and	edx, 63
	or	edx, esi
	cmp	cl, -16
	jb	.LBB0_7
	movzx	ecx, byte ptr [rdi + 3]
	and	eax, 7
	shl	eax, 18
	shl	edx, 6
	and	ecx, 63
	or	ecx, edx
	or	eax, ecx
	ret
.LBB0_4:
	shl	eax, 6
	or	eax, esi
	ret
.LBB0_7:
	shl	eax, 12
	or	eax, edx
	ret
```
2021-11-21 17:05:55 +01:00
..
condvar Migrate standard library away from compare_and_swap 2020-12-22 12:19:46 +01:00
memchr Move std::memchr to sys_common 2021-05-14 03:54:46 +02:00
net std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
remutex Fix more “a”/“an” typos 2021-08-22 16:35:29 +02:00
thread_local_key std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
thread_parker Migrate standard library away from compare_and_swap 2020-12-22 12:19:46 +01:00
wtf8 Auto merge of #86463 - fee1-dead:fixed-encode_wide, r=m-ou-se 2021-06-20 02:18:51 +00:00
backtrace.rs Apply clippy suggestions 2021-10-09 18:56:01 +02:00
condvar.rs Make it possible to have unboxed condvars on specific platforms. 2020-10-02 09:47:08 +02:00
fs.rs Move the implementation of Path::exists to sys_common::fs so platforms can specialize it 2021-05-19 23:54:56 +01:00
io.rs STD support for the ESP-IDF framework 2021-08-10 12:09:00 +03:00
memchr.rs Move std::memchr to sys_common 2021-05-14 03:54:46 +02:00
mod.rs Use target_family = "wasm" 2021-11-10 08:35:42 -08:00
mutex.rs Remove lifetime from StaticMutex and assume 'static. 2020-10-14 09:52:03 +02:00
net.rs add TcpStream::set_linger and TcpStream::linger 2021-08-30 13:42:52 -04:00
process.rs Add #[must_use] to remaining std functions (O-Z) 2021-10-30 23:37:32 -04:00
remutex.rs Use Pin for the 'don't move' requirement of ReentrantMutex. 2020-12-08 22:57:57 +01:00
rwlock.rs Multiple improvements to RwLocks 2021-06-01 09:07:55 +02:00
tests.rs std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
thread.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
thread_info.rs Merge two THREAD_INFO.with and following RefCell borrow 2021-09-16 15:24:53 +02:00
thread_local_dtor.rs Fix a typo in thread_local_dtor.rs 2021-03-14 16:39:29 +09:00
thread_local_key.rs Migrate standard library away from compare_and_swap 2020-12-22 12:19:46 +01:00
wtf8.rs libcore: assume the input of next_code_point and next_code_point_reverse is UTF-8-like 2021-11-21 17:05:55 +01:00