javasgl

step by step


  • Home

  • Archives

  • Tags

  • Categories

  • About

  • Search

读书清单(备忘)

Posted on 2017-08-19 | In notes | Visitors

2017读书清单

进行中&计划中

  • 《Go并发编程实战》 –郝林
  • 《App 后台开发运维和架构实践》–曾健生
  • 《重构–改善既有代码的设计》 – 中文版
  • 《高性能网站架构实战》 – 刘鑫
  • 《构建高性能Web站点》 – 郭欣
  • 《设计模式之禅》 – 秦小波
  • 《go In Action》(Go语言实战)–中文版
  • 《the way to go》(go语言程序设计)–中文版
    ….

已读

  • 《Go By Example》– github
  • 《build-web-application-with-golang》–github
  • 《Go语言编程》 – 许式伟
  • 《Go语言最佳实践》– pdf
  • 《深入理解PHP内核》– php-internal.com

^_^ 任务艰巨~~~~

使用 & 代替 % 来判断整数奇偶性

Posted on 2017-08-08 | In notes | Visitors

一般情况下,判断整数的奇偶性都会使用取模预算, 性能方面没有测试,但是由于机器可以直接操作二进制,应该会比较快,不过这点性能提升一般情况下对整体性能的影响不大,可以忽略不计。

1
2
3
4
5
if num%2==0 {
fmt.Println("even")
} else {
fmt.Println("odd")
}

不过,还有一种方式也是类似,使用 按位与 来判断整数奇偶性:

1
2
3
4
5
if num&1==0 {
fmt.Println("even")
} else {
fmt.Println("odd")
}

也能达到相同的效果。

类似的,使用二进制运算也可以进行乘除法的运算:
乘法左移:

1
2
3
4
5
//a = a * 4
a = a << 2

//b = b * 8
b = b << 3

除法右移:

1
2
3
4
5
//a = a / 4
a = a >> 2

//b = b / 8
b = b >> 3

这些都是一些二进制运算的技巧,记下备忘。

阅读 php 源码,使用 vld 扩展查看 opcode

Posted on 2017-08-03 | In php | Visitors

php 虽然是一门动态语言,但是它也有一个编译的过程,这个过程经过词法分析、语法分析,最终生成 Zend 引擎可以执行的 opcode 指令,类似于 java 的字节码。

要查看一段代码对应的 opcode ,可以使用 vld 扩展 来查看。

安装

安装 vld 和安装 php 其他的扩展没有任何区别,下载源码、编译、安装等…

1
2
3
4
5
6
tar zxf vld-0.14.0.tar.gz
cd vld-0.14.0
phpize
./configure
make
make install

记得要修改 php.ini 启用 vld 扩展:

1
2
[vld]
extensions=vld.so

Read more »

阅读 php 源码,ctags 配合 vim 实现代码跳转

Posted on 2017-08-01 | In php | Visitors

在阅读 php 源码的时候,为了方便跳转到相应的函数定义的位置,需要使用 ctags 来生成 tags 文件,再配合 vim 来实现跳转。

安装 ctags

macOS 上使用 ctags 非常简单,一般都预装了 ctags 。

如果没有安装,可以使用 brew install ctags 来安装。

tags 文件

在 php 源码根目录,执行 ctags -R, 就会在当前目录下生成一个名为 tags 的 文件。

1
2
3
4
5
6
7
8
9
10
~/codes/php-src(master*) » tail -n 20 tags                                                                                                                                       
zval_marked_grey Zend/zend_gc.h /^ uint32_t zval_marked_grey;$/;" m struct:_zend_gc_globals
zval_object_property_dump ext/standard/var.c /^static void zval_object_property_dump(zval *zv, zend_ulong index, zend_string *key, int level) \/* {{{ *\/$/;" f file:
zval_opt_copy_ctor Zend/zend_variables.h /^#define zval_opt_copy_ctor(/;" d
zval_possible_root Zend/zend_gc.h /^ uint32_t zval_possible_root;$/;" m struct:_zend_gc_globals
zval_ptr_dtor Zend/zend_execute.c /^#define zval_ptr_dtor(/;" d file:
zval_ptr_dtor Zend/zend_execute.c /^#undef zval_ptr_dtor$/;" d file:
zval_ptr_dtor Zend/zend_variables.h /^#define zval_ptr_dtor(/;" d
zval_ptr_dtor_nogc Zend/zend_variables.h /^#define zval_ptr_dtor_nogc(/;" d
zval_ptr_dtor_wrapper Zend/zend_variables.h /^#define zval_ptr_dtor_wrapper /;" d
Read more »

golang 匿名 struct 的使用方式

Posted on 2017-07-08 | In go | Visitors

编程中有时候需要一个临时的 struct 来封装数据,而这个 struct 的结构在其它地方又不会被二次复用,可以使用匿名 struct 来实现。

主要有两种方式,如下:
第一种方式,通过 var 初始化

1
2
3
var user struct{Name string;age int}
user.Name = "name"
user.age = 18

第二种方式,直接初始化

1
json.Marshal(struct{Name string;age int}{"name",18})

或者:

1
2
3
4
json.Marshal(struct{
Name string
age int
}{"name",18})

1…789…12
javasgl

javasgl

A journey of a thousand miles begins with single step

60 posts
13 categories
94 tags
RSS
GitHub Wechat
© 2020 javasgl
Powered by Hexo
Theme - NexT.Mist
0%