Skip to content

Conversation

@moling3650
Copy link

修复get方法的一个bug:当配置文件已缓存而$name不存在时,没有正确返回false。
整合get和all方法:两者的代码相似度太高,可以重用封装一个方法

原来的get方法有bug,当缓存过的文件但配置项的名不对时,没有正确的返回false,而get和all的代码重复率太高,完全可以整合重用。
Copy link
Owner

@kphcdr kphcdr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得不应该把两个方法合并到一起去。因为可能会扩展一个把配置存储在mysql中的功能,这时候对于get和all方法的分开使用的效率会更加明显

@moling3650
Copy link
Author

为什么说get和all分开的效率比较明显?get的前半部分都必须和all一样的,要不然就是验证不够完备,get的复杂度比以前增加1(多了is_null($name) 的判断)。

if(isset(self::$conf[$file][$name])) {
     return self::$conf[$file][$name];
else
    ...

这种写法只是看上去效率很高,但实际上如果文件已经缓存过,而$name是不存在时,还是要重复去include的。为了提高O(1)的性能写多十行完全一样的代码,这决定值得商酌。储存mysql的道理也是一样的,也是多了一句is_null($name) 的判断,其他流程是完全一样的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants