Skip to content

Commit 1b20767

Browse files
committed
Minor grammar/spelling fixes to the "Static and Dynamic Dispatch" doc
1 parent 522d09d commit 1b20767

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/doc/trpl/static-and-dynamic-dispatch.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ inlining and hence usually higher performance. It also has some downsides:
8484
causing code bloat due to many copies of the same function existing in the
8585
binary, one for each type.
8686

87-
Furthermore, compilers aren’t perfect and may “optimise” code to become slower.
87+
Furthermore, compilers aren’t perfect and may “optimize” code to become slower.
8888
For example, functions inlined too eagerly will bloat the instruction cache
8989
(cache rules everything around us). This is part of the reason that `#[inline]`
9090
and `#[inline(always)]` should be used carefully, and one reason why using a
@@ -104,15 +104,15 @@ objects, like `&Foo` or `Box<Foo>`, are normal values that store a value of
104104
known at runtime. The methods of the trait can be called on a trait object via
105105
a special record of function pointers (created and managed by the compiler).
106106

107-
A function that takes a trait object is not specialised to each of the types
107+
A function that takes a trait object is not specialized to each of the types
108108
that implements `Foo`: only one copy is generated, often (but not always)
109109
resulting in less code bloat. However, this comes at the cost of requiring
110110
slower virtual function calls, and effectively inhibiting any chance of
111111
inlining and related optimisations from occurring.
112112

113113
Trait objects are both simple and complicated: their core representation and
114114
layout is quite straight-forward, but there are some curly error messages and
115-
surprising behaviours to discover.
115+
surprising behaviors to discover.
116116

117117
### Obtaining a trait object
118118

@@ -140,13 +140,13 @@ and casts are identical.
140140

141141
This operation can be seen as "erasing" the compiler's knowledge about the
142142
specific type of the pointer, and hence trait objects are sometimes referred to
143-
"type erasure".
143+
as "type erasure".
144144

145145
### Representation
146146

147147
Let's start simple, with the runtime representation of a trait object. The
148148
`std::raw` module contains structs with layouts that are the same as the
149-
complicated build-in types, [including trait objects][stdraw]:
149+
complicated built-in types, [including trait objects][stdraw]:
150150

151151
```rust
152152
# mod foo {
@@ -223,14 +223,14 @@ static Foo_for_String_vtable: FooVtable = FooVtable {
223223
The `destructor` field in each vtable points to a function that will clean up
224224
any resources of the vtable's type, for `u8` it is trivial, but for `String` it
225225
will free the memory. This is necessary for owning trait objects like
226-
`Box<Foo>`, which need to clean-up both the `Box` allocation and as well as the
226+
`Box<Foo>`, which need to clean-up both the `Box` allocation as well as the
227227
internal type when they go out of scope. The `size` and `align` fields store
228228
the size of the erased type, and its alignment requirements; these are
229229
essentially unused at the moment since the information is embedded in the
230-
destructor, but will be used in future, as trait objects are progressively made
231-
more flexible.
230+
destructor, but will be used in the future, as trait objects are progressively
231+
made more flexible.
232232

233-
Suppose we've got some values that implement `Foo`, the explicit form of
233+
Suppose we've got some values that implement `Foo`, then the explicit form of
234234
construction and use of `Foo` trait objects might look a bit like (ignoring the
235235
type mismatches: they're all just pointers anyway):
236236

0 commit comments

Comments
 (0)