Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
0xf90c committed Jun 14, 2024
1 parent 4948ca7 commit d85b7e2
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions rustbook-uz/src/ch15-04-rc.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,23 @@ Biz scopeni ichiga `Rc<T>`ni kiritsh uchun `use` statementini qo'shishimiz kerak
chunki u muqaddimani ichida bo'lmagani uchun. `main`ni ichida 5 va 10ni saqlovch ro'yxatni
yaratamiz va uni `a`ga tegishli yangi `Rc<List>`ga joylashtiramiz. Keyin esa `b` va `c` yaratganimizda, `Rc::clone` funksiyasini chaqiramiz va argument sifatida `a`ga tegishli bo'lgan `Rc<List>`ga o'tkazib yuboramiz.

We could have called `a.clone()` rather than `Rc::clone(&a)`, but Rust’s
convention is to use `Rc::clone` in this case. The implementation of
`Rc::clone` doesn’t make a deep copy of all the data like most types’
implementations of `clone` do. The call to `Rc::clone` only increments the
reference count, which doesn’t take much time. Deep copies of data can take a
lot of time. By using `Rc::clone` for reference counting, we can visually
distinguish between the deep-copy kinds of clones and the kinds of clones that
increase the reference count. When looking for performance problems in the
code, we only need to consider the deep-copy clones and can disregard calls to
`Rc::clone`.
`Rc::clone(&a)`ning o'rniga biz `a.clone()` chaqirishimiz mumkin edi, lekin Rust
qoidalariga muofiq ushbu holatda `Rc::clone` ishlatgan ma'qul. `Rc:clone`ning implementatsiyasi `clone`ning ko'p implementatsiya turiga o'xshab ma'lumotlarni to'liq
nusxa olmaydi.
qoidalariga muofiq ushbu holatda `Rc::clone` ishlatgan ma'qul. `Rc::clone`ning implementatsiyasi `clone`ning ko'p implementatsiya turiga o'xshab ma'lumotlarni to'liq
nusxa olmaydi. `Rc::clone`ning chaqirilishi referenslarning sonini ko'paytiradi, va shuning uchun ham ko'p vaqt olmaydi. Ma'lumotlarni to'liq nusxalash esa ko'p vaqt talab etadi. Referenslarni hisoblash uchun `Rc::clone`ni ishlatsak, biz to'liq nusxalangan bilan referenslar soni ortgan nusxalar orasidagi farqni tasavvur qilishimiz mumkin. Kodning unumdorlik muammolarini qidirayotganimizda, bizga faqat to'liq nusxalangan nusxalarga e'tibor qaratib, `Rc::clone`ning chaqirilishini e'tiborga olmasak ham bo'ladi.

### Cloning an `Rc<T>` Increases the Reference Count
### `Rc<T>`ni nusxalash Referenslar hisobini orttiradi

Let’s change our working example in Listing 15-18 so we can see the reference
counts changing as we create and drop references to the `Rc<List>` in `a`.
`a`da referenslarni yaratib va uni `Rc<List>`ga drop qilib referenslar sonini ortayotganligini keling bizning ishlab turgan 15-18-ro'yxatimizdagi misolga o'zgartirish kiritib ko'raylik,

In Listing 15-19, we’ll change `main` so it has an inner scope around list `c`;
then we can see how the reference count changes when `c` goes out of scope.
15-19-ro'yxatda, `main`ni o'zgartirib ko'raylik chunki uning ichki scope(doirasi) `c`ro'yxatining atrofida shundan so'ng biz `c` scope(doirasida) chiqqanda qanday qilib referenslar soni ortayotganini ko'ramiz.

<span class="filename">Filename: src/main.rs</span>
<span class="filename">Fayl-nomi: src/main.rs</span>

```rust
{{#rustdoc_include ../listings/ch15-smart-pointers/listing-15-19/src/main.rs:here}}
```

<span class="caption">Listing 15-19: Printing the reference count</span>
<span class="caption">15-19-ro'yxat: Referens soni ortayotganligini print qilish</span>

At each point in the program where the reference count changes, we print the
reference count, which we get by calling the `Rc::strong_count` function. This
Expand Down

0 comments on commit d85b7e2

Please sign in to comment.