Skip to content

Commit

Permalink
writing map article
Browse files Browse the repository at this point in the history
  • Loading branch information
bootun committed Jan 15, 2022
1 parent 0e1ef37 commit 6fc0c70
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Go剖析系列
## 目录
- [数组剖析](./articles/1-array.md)
- [切片剖析](./articles/2-slice.md)
- [map剖析(写作中)](./articles/3-map.md)
- [附录1:如何寻找源码位置](./articles/appendix/1-source.md)

## 关于
Expand Down
28 changes: 28 additions & 0 deletions articles/3-map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Map剖析
===
## 初始化
## 编译时的map
节点的op类型
ir.OMAPLIT
walk.maplit
```Go
func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
// make the map var
// 虽然这里传入的op类型为ir.OMAKE,但最终生成代码时并
// 不一定会有makemap,比如当map被分配至栈上,详细请看
// walk.walkMakeMap
a := ir.NewCallExpr(base.Pos, ir.OMAKE, nil, nil)
...
// 如果要初始化的条目大于25,则将其放入数组循环赋值
if len(entries) > 25 {

// for i = 0; i < len(vstatk); i++ {
// map[vstatk[i]] = vstate[i]
// }
return
}
// 对于很少数量的条目,直接赋值

// Build list of var[c] = expr.
}
```

0 comments on commit 6fc0c70

Please sign in to comment.