Commit 2b1eaf35 authored by Jacksgong's avatar Jacksgong

refactor(all post md): add Creative Commons Attribution-NonCommercial 3.0…

refactor(all post md): add Creative Commons Attribution-NonCommercial 3.0 license to all posts's bottom
parent 42317124
......@@ -24,4 +24,10 @@ tags:
其实有一件事,当下我觉得比较烦恼,不过也却是个不争的事实,在一些大公司里,实习生没有任何实质的名分,各方面都会比临时工略低一等。不过多亏过几个月就不再是实习生了。虽然大一暑假起我就几乎游荡在各个公司做开发,虽然以前也做过研究生的毕业设计的外包,虽然相比没来实习的,过几个月应该和正式员工没有什么差别。但这就是制度吧。虽然我也经常思考是否和大伙一样在年后回学校,毕业以后再过来。但是万事有得有失,我觉得,目前多历练,并不是什么坏事,如果现在问我,就现状,有什么能够加快我下个阶段的步伐,那就是留在这里,更加努力。
新的一年,虽然我从来不信什么分界线,但是我希望自己能够多做一些总结,多做一点思考,多一点努力,道路漫长,与其与自己述说,不如录入成文。
\ No newline at end of file
新的一年,虽然我从来不信什么分界线,但是我希望自己能够多做一些总结,多做一点思考,多一点努力,道路漫长,与其与自己述说,不如录入成文。
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -14,7 +14,7 @@ tags:
视频标题: 从360手机卫士的开发历程看如何实施大型移动应用开发
视频地址: http://www.infoq.com/cn/presentations/from-360-development-see-big-mobile-application-development
视频地址: http://www.infoq.com/cn/presentations/from-360-development-see-big-mobile-application-development
## 宗旨:
......@@ -123,4 +123,10 @@ tags:
1. 人员方面,现在水涨船高,人员可以多挖掘C++或做pc开发等的开发人员。
2. 代码方面,通过插件化,整个团队分模块达到解耦,独立维护,加快各模块独立维护速度。
3. 研发流程: 重视build break问题
4. 组织架构: 小团队;少开大会;专人维护Build系统;专门的架构组;专门的质量改进组(高手重点);专门的自动化测试组;每周召开质量会
\ No newline at end of file
4. 组织架构: 小团队;少开大会;专人维护Build系统;专门的架构组;专门的质量改进组(高手重点);专门的自动化测试组;每周召开质量会
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -95,3 +95,9 @@ myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
android:paddingRight="2dp" >
```
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -13,7 +13,7 @@ tags:
项目组成:AIDL_SERVICE_LIB[库项目]、AIDL_CLIENT。
<!--more-->
### 那么主要的需要实现的功能通过几个AIDL文件就可以获知:
### IAIDLService.aidl:
......@@ -28,7 +28,7 @@ tags:
void registerCallback(IServiceCallback paramIServiceCallback);
void unregisterCallback(IServiceCallback paramIServiceCallback);
}
### IServiceCallback.aidl:
package cn.dreamtobe.aidl.service;
import cn.dreamtobe.aidl.service.Book;
......@@ -36,7 +36,7 @@ tags:
void handlerCommEvent(int msgId, int param);
void callbackBookEvent(int cmd, in Book book);
}
###
最终目的是需要跨进程,AIDLService通过回调通知AIDLClient处理并传递有关值,并且AIDLClient可以通过AIDLService中定义好的AIDL有关方法,进行通知或取值。
......@@ -44,3 +44,9 @@ tags:
![image](https://github.com/Jacksgong/AIDL_COMMUNICATE-CALLBACK/raw/master/aidl_readme/raw/bind_succeed.png)
![image](https://github.com/Jacksgong/AIDL_COMMUNICATE-CALLBACK/raw/master/aidl_readme/raw/unbind.png)
![image](https://github.com/Jacksgong/AIDL_COMMUNICATE-CALLBACK/raw/master/aidl_readme/raw/unbind_request.png)
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -407,6 +407,11 @@ public abstract class BaseActivity extends Activity {
}
}
```
至此,已经简单的通过Messenger完成进程间通信。
— Jacksgong Share&Study.
\ No newline at end of file
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -12,7 +12,7 @@ tags:
## 1. 申明
本项目library_gallery基于Truba的AndroidTouchGallery,往上封装一层,实现简单快速实现Viewpager上协调图片的缩放以及数据来源的自动选择.
## 2. 拓展部分
实现相关接口,底层即可完成自动选择从网路加载、从本地文件加载或者从Cache加载
......@@ -47,8 +47,8 @@ tags:
return Path.IV + AppUtil.md5(url);
}
}
public class DemoHorizontalGalleryActivity extends Activity {
private GalleryViewPager mViewPager;
......@@ -70,7 +70,7 @@ tags:
mViewPager.setAdapter(mAdapter);
}
}
详情可参看GallerySample
## 3. 运行效果
......@@ -84,3 +84,9 @@ License
## 4. 源码
GITHUB: https://github.com/Jacksgong/Android-Touch-Gallery
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -22,7 +22,7 @@ ps: 目前架构基于ContentProvier
-------
1. BaseContentProvider 负责数据库的规范
2. BaseTableFields 规范数据表 字段(默认字段:_id, createAt, modifiedAt)
2. BaseTableFields 规范数据表 字段(默认字段:`_id`, `createAt`, `modifiedAt`)
3. BaseTableHelper 负责数据表 规范(表名、主键、默认查询结果排序、表创建、表升级)
4. BaseTableOperator 提供常用数据表的操作以及操作规范(某人已带功能:插入、更新、删除、搜索、数量、是否存在)
5. CustomTableHelper 常用表规范(默认查询结果排列顺序、默认主键)
......@@ -36,155 +36,169 @@ ps: 目前架构基于ContentProvier
####**1. 创建SampleDB数据库**(注意在AndroidManifest.xml中申明ContentProvider)
public class SampleDB extends BaseContentProvider {
public final static String DATABASE_NAME = "sample.db";
public final static String AUTHORITY = "sampledb";
public final static int DATABASE_VERSION = 1;
public SampleDB() {
super(AUTHORITY);
}
@Override
protected HashMap<String, BaseTableHelper> createAllTableHelper() {
final HashMap<String, BaseTableHelper> hashMap = new HashMap<String, BaseTableHelper>();
// 需要提供各表的Helper
final UserInfoHelper userInfoHelper = UserInfoHelper.getImpl();
hashMap.put(userInfoHelper.getTableName(), userInfoHelper);
return hashMap;
}
@Override
protected String getDatabaseName() {
return DATABASE_NAME;
}
@Override
protected int getDatabaseVersion() {
return DATABASE_VERSION;
}
}
```
public class SampleDB extends BaseContentProvider {
public final static String DATABASE_NAME = "sample.db";
public final static String AUTHORITY = "sampledb";
public final static int DATABASE_VERSION = 1;
public SampleDB() {
super(AUTHORITY);
}
@Override
protected HashMap<String, BaseTableHelper> createAllTableHelper() {
final HashMap<String, BaseTableHelper> hashMap = new HashMap<String, BaseTableHelper>();
需要提供各表的Helper
final UserInfoHelper userInfoHelper = UserInfoHelper.getImpl();
hashMap.put(userInfoHelper.getTableName(), userInfoHelper);
return hashMap;
}
@Override
protected String getDatabaseName() {
return DATABASE_NAME;
}
@Override
protected int getDatabaseVersion() {
return DATABASE_VERSION;
}
}
```
####**2. UserInfo表字段**(name, sex, age)
public class UserInfoFields extends BaseTableFields {
public final static String NAME = "name";
public final static String SEX = "sex";
public final static String AGE = "age";
public UserInfoFields() {
}
public UserInfoFields(final Cursor c) {
super(c);
}
public void setName(final String name) {
put(NAME, name);
}
public String getName() {
return (String) get(NAME);
}
public void setSex(final String sex) {
put(SEX, sex);
}
public String getSex() {
return (String) get(SEX);
}
public void setAge(final String age) {
put(AGE, age);
}
public String getAge() {
return (String) get(AGE);
}
@Override
public void put(Cursor c) {
if (c == null || c.isClosed() || c.isAfterLast()) {
return;
}
set_Id(c.getInt(c.getColumnIndexOrThrow(_ID)));
setName(c.getString(c.getColumnIndexOrThrow(NAME)));
setSex(c.getString(c.getColumnIndexOrThrow(SEX)));
setAge(c.getString(c.getColumnIndexOrThrow(AGE)));
}
}
```
public class UserInfoFields extends BaseTableFields {
public final static String NAME = "name";
public final static String SEX = "sex";
public final static String AGE = "age";
public UserInfoFields() {
}
public UserInfoFields(final Cursor c) {
super(c);
}
public void setName(final String name) {
put(NAME, name);
}
public String getName() {
return (String) get(NAME);
}
public void setSex(final String sex) {
put(SEX, sex);
}
public String getSex() {
return (String) get(SEX);
}
public void setAge(final String age) {
put(AGE, age);
}
public String getAge() {
return (String) get(AGE);
}
@Override
public void put(Cursor c) {
if (c == null || c.isClosed() || c.isAfterLast()) {
return;
}
set_Id(c.getInt(c.getColumnIndexOrThrow(_ID)));
setName(c.getString(c.getColumnIndexOrThrow(NAME)));
setSex(c.getString(c.getColumnIndexOrThrow(SEX)));
setAge(c.getString(c.getColumnIndexOrThrow(AGE)));
}
}
```
####**3. UserInfo表规范**
public class UserInfoHelper extends CustomTableHelper {
public final static String TABLE_NAME = "user_info";
private final static class ClassHolder {
private final static UserInfoHelper INSTANCE = new UserInfoHelper();
}
public static UserInfoHelper getImpl() {
return ClassHolder.INSTANCE;
}
@Override
public String getTableName() {
return TABLE_NAME;
}
@Override
public void onDataBaseCreate(SQLiteDatabase db) {
final String create = getCustomCreatePre() + UserInfoFields.NAME + " TEXT," + UserInfoFields.SEX + " TEXT," + UserInfoFields.AGE + " TEXT);";
db.execSQL(create);
}
}
```
public class UserInfoHelper extends CustomTableHelper {
public final static String TABLE_NAME = "user_info";
private final static class ClassHolder {
private final static UserInfoHelper INSTANCE = new UserInfoHelper();
}
public static UserInfoHelper getImpl() {
return ClassHolder.INSTANCE;
}
@Override
public String getTableName() {
return TABLE_NAME;
}
@Override
public void onDataBaseCreate(SQLiteDatabase db) {
final String create = getCustomCreatePre() + UserInfoFields.NAME + " TEXT," + UserInfoFields.SEX + " TEXT," + UserInfoFields.AGE + " TEXT);";
db.execSQL(create);
}
}
```
####**4. UserInfo表操作**(实现下面,就已经带有了这些功能:插入、更新、删除、搜索、数量、是否存在)
public class UserInfoOperator extends BaseTableOperator<UserInfoFields, UserInfoHelper> {
private final static class ClassHolder {
private final static UserInfoOperator INSTANCE = new UserInfoOperator(SampleApplication.getContext(), UserInfoHelper.getImpl());
}
public static UserInfoOperator getImpl() {
return ClassHolder.INSTANCE;
}
public UserInfoOperator(Context context, UserInfoHelper helper) {
super(context, helper);
}
@Override
public Uri getUri() {
return getTableHelper().getContentUri(SampleDB.AUTHORITY);
}
@Override
protected List<UserInfoFields> createColumns(Cursor c) {
if (c == null || c.isClosed() || c.isAfterLast()) {
return null;
}
List<UserInfoFields> list = new ArrayList<UserInfoFields>();
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
list.add(new UserInfoFields(c));
}
return list;
}
}
```
public class UserInfoOperator extends BaseTableOperator<UserInfoFields, UserInfoHelper> {
private final static class ClassHolder {
private final static UserInfoOperator INSTANCE = new UserInfoOperator(SampleApplication.getContext(), UserInfoHelper.getImpl());
}
public static UserInfoOperator getImpl() {
return ClassHolder.INSTANCE;
}
public UserInfoOperator(Context context, UserInfoHelper helper) {
super(context, helper);
}
@Override
public Uri getUri() {
return getTableHelper().getContentUri(SampleDB.AUTHORITY);
}
@Override
protected List<UserInfoFields> createColumns(Cursor c) {
if (c == null || c.isClosed() || c.isAfterLast()) {
return null;
}
List<UserInfoFields> list = new ArrayList<UserInfoFields>();
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
list.add(new UserInfoFields(c));
}
return list;
}
}
```
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -90,4 +90,10 @@ androidpn-client(客户端)、Androidpn-tomcat(服务端)
jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
4. 创建数据库(假设上面数据库名填写test):
`create database test;`
5. 完成配置
\ No newline at end of file
5. 完成配置
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -22,20 +22,20 @@ tags:
### 两个缓存池支持并发操作,但这里的支持并发,对于本library而言,外部多线程使用时,注意同步。
这里有几个需要考究的地方,一个就是缓存池类型的选用,主要考究参考如下:
ConcurrentHashMap 允许在不阻塞线程 (block threads)的情况下,几个线程同时修改Map。
Collections.synchronizedMap(map) 创建一个阻塞Map (blocking map), 这会降低map性能。如果需要确保数据的 一致性,使得每个线程都有Map 的即时视图,那么可以使用它
参考网友测试数据:[http://www.java-forums.org/new-java/13840-hashmap-vs-skiplistmap.html](http://www.java-forums.org/new-java/13840-hashmap-vs-skiplistmap.html)
在4线程1.6万数据的条件下,ConcurrentHashMap 存取速度是ConcurrentSkipListMap 的4倍左右。
但ConcurrentSkipListMap有几个ConcurrentHashMap 不能比拟的优点:
1、ConcurrentSkipListMap 的key是有序的。
2、ConcurrentSkipListMap 支持更高的并发。ConcurrentSkipListMap 的存取时间是log(N),和线程数几乎无关。也就是说在数据量一定的情况下,并发的线程越多,ConcurrentSkipListMap越能体现出他的优势。
3、的使用Vector或Collections.synchronizedList(List<T>)的方式来解决该问题。但是这并没有效果!虽然在列表上add(),remove()和get()方法现在对线程是安全的,但遍历时仍然会抛出ConcurrentModificationException!在你遍历在列表时,你需要在该列表上使用同步,同时,在使用Quartz修改它时,也需要使用同步机制。
重点提下,所有的线程安全都是对于内部而言
因此我们两个缓存池如下:
......@@ -54,24 +54,24 @@ tags:
*/
private Map<String, byte[]> mCache = Collections.synchronizedMap(new LinkedHashMap<String, byte[]>(INIT_CAPACITY, LOAD_FACTOR, true));
private Map<String, WeakReference<byte[]>> mWeakCache = new ConcurrentHashMap<String, WeakReference<byte[]>>();
也许你会问为什么做了这些分析,强引用缓存池还使用Collections.synchronizedMap,我想coderanch.com论坛的Steve已经给我做出了答复:
You will have to come up with the requirements for your storage structure to figure out which one is best. There are two big differences:
You will have to come up with the requirements for your storage structure to figure out which one is best. There are two big differences:
1) The LinkedHashMap is ordered but not thread safe
1) The LinkedHashMap is ordered but not thread safe
2) The ConcurrentHashMap is thread safe but not ordered
2) The ConcurrentHashMap is thread safe but not ordered
If you need an ordered thread safe map, then maybe ConcurrentSkipListMap might be a better choice (but maybe not...).
If you need an ordered thread safe map, then maybe ConcurrentSkipListMap might be a better choice (but maybe not...).
If you wanted the ordering of LinkedHashMap in a thread safe structure, your concerns should be:
- How much work would it take to make LinkedHashMap thread safe?
- Do you trust yourself to be able to make it thread safe?
- Can you make it thread safe and still efficient?
If you wanted the ordering of LinkedHashMap in a thread safe structure, your concerns should be:
- How much work would it take to make LinkedHashMap thread safe?
- Do you trust yourself to be able to make it thread safe?
- Can you make it thread safe and still efficient?
versus
- How much work would it take to make ConcurrentSkipListMap (or ConcurrentHashMap) sort like the LinkedHashMap?At first blush, this might seem easy (CSKLM uses a comparator, so just make a comparator for access time) but it won't be (you would be sorting on something other than the Key (insertion/access order), your structure would have to change with access, not just insertion, iteration would be affected...).
versus
- How much work would it take to make ConcurrentSkipListMap (or ConcurrentHashMap) sort like the LinkedHashMap?At first blush, this might seem easy (CSKLM uses a comparator, so just make a comparator for access time) but it won't be (you would be sorting on something other than the Key (insertion/access order), your structure would have to change with access, not just insertion, iteration would be affected...).
- Is the Map you come up with efficient enough to use?
因此目前强引用缓存池,这么做是折中的选择,当然还有很大的优化空间。我承认这里完全可以我们自己写一个线程安全的LinkedHashMap或支持LRU的ConcurrenthashMap,因为我们有他们的源码与详细的分析文稿。暂时如此,以后抽空优化。
......@@ -90,9 +90,9 @@ tags:
import cn.dreamtobe.library.cache.util.TransUtil;
/**
*
*
* @describe Proxy
*
*
* @author Jacksgong
* @since 2013-12-16 下午8:47:17
* @Web http://blog.dreamtobe.cn/1470.html
......@@ -157,7 +157,7 @@ tags:
// Parcelable
/**
*
*
* @param key
* @param p
* 这里选用Parcelable的原因
......@@ -257,3 +257,9 @@ tags:
### 最后,作为缓存入口,它的功能绝非止于此。
抽空我会进行数据分块处理等拓展(对外提供接口),并且优化弱引用池类型与文件缓存处理,并做一些考究。
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -177,3 +177,9 @@ tags:
分包(octet-stuffing、octet-counting、connect-blasting)、并发处理(序列号、命令号)、兼容性&拓展性(版本号,压缩算法、加密算法)、精简(严格按照packed所需大小)
###### 3. 时序(先后顺序)
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -50,13 +50,13 @@ tags:
//表
@DatabaseTable(tableName = "accounts")
public class Account {
@DatabaseField(id = true)
private String name;
@DatabaseField(canBeNull = false)
private String password;
// getters & setters
}
```
......@@ -70,7 +70,7 @@ TableUtils.createTable(connectionSource, Account.class);
// instantiate the DAO to handle Account with String id
Dao<Account, String> accountDao =
databaseHelper.getDao(Account.class);
//create an instance of Account
String name = "Jim Smith";
Account account = new Account(name, "_secret");
......@@ -109,10 +109,10 @@ where.query();
// 表
public class Account extends RealmObject {
private String name;
private String password;
// getters & setters
}
```
......@@ -217,7 +217,7 @@ recyclerView.scrollToPosition(0);
ps: support包有一个简单的判断是Android L的静态方法:`versionUtils.isAtLeastL`
#### LayoutTransitions ( API 1开始就有):
#### LayoutTransitions ( API 1开始就有):
非常强大,布局变化或者Visible/Gone这类的切换动画。考虑用这个,简单强大。
......@@ -235,7 +235,7 @@ ps: support包有一个简单的判断是Android L的静态方法:`versionUtils.
#### 1. View层级不要太深
保持Layout平坦,不要有深层级
#### 2. 谨慎创建对象(避免在View draw流程中(onMearsure、onLayout、onDraw...)创建对象
因为gc会带来很多帧率上的损失
......@@ -255,7 +255,7 @@ ps: support包有一个简单的判断是Android L的静态方法:`versionUtils.
**千万避免在View中设置透明度**,特别是在自定义的View上(一般来说ImageView、TextView(ButtonView..)是没有问题的),Falcon作者,在一次检测GPU呈现模式的时候,发现一个设置透明度,导致了Frame的渲染慢了一倍多。
具体原因是由于,一旦设置了Alpha,每次draw 那个View都不得不 清除绘制缓存(Flush Buffer),然后再绘制到屏幕上,效果如右图(顶部的那几个小点setAlpha(0.5*255))。
![](/img/Falcon-font.png)
#### 2. 调试CPU过渡绘制
......@@ -347,3 +347,9 @@ Joaquim不喜欢 赤裸裸的截图,喜欢重构布局、装饰以后的截图
1. 通过尽量快的应答用户,让用户感觉他们也是产品项目的一员。
2. 通过用户反馈,来生成项目接下来要做的清单。
3. 解决用户的问题,因为他们将会成为你最好的客户。
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -12,8 +12,8 @@ tags:
python.
### 二. Cause
1. __offset() method is not fast enough.
2. for get a varaible may need to calls __offset() method many times.
1. `__offset()` method is not fast enough.
2. for get a varaible may need to calls `__offset()` method many times.
### 三. Effect
1. Add has set method for flatbuffer file.
......@@ -25,7 +25,9 @@ python.
origin:
public int top() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
```
public int top() { int o = __offset(4); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
```
convert to:
......@@ -33,14 +35,16 @@ convert to:
public boolean has_top_cache = false;
public int top_cache;
public int top() { if ( has_top_cache ) { return top_cache; } int o = __offset(4); top_cache = o != 0 ? bb.getInt(o + bb_pos) : 0; has_top_cache= true; return top_cache; }
public boolean hasSetValue_top = false;
public boolean hasSetValue_top = false;
public boolean hasSet_top() { if ( hasSetValue_top ) { return true; } if ( has_top_cache ) { return top_cache != 0; } int o = __offset(4); if (o == 0) { has_top_cache = true; top_cache = 0; return false; } else { hasSetValue_top = true; return true; } }
```
origin:
public String fontFamily(int j) { int o = __offset(10); return o != 0 ? __string(__vector(o) + j * 4) : null; }
```
public String fontFamily(int j) { int o = __offset(10); return o != 0 ? __string(__vector(o) + j * 4) : null; }
```
convert to:
```
......@@ -240,4 +244,10 @@ def main():
main()
```
\ No newline at end of file
```
---
> © 2016, Jacksgong(blog.dreamtobe.cn). Licensed under the Creative Commons Attribution-NonCommercial 3.0 license (This license lets others remix, tweak, and build upon a work non-commercially, and although their new works must also acknowledge the original author and be non-commercial, they don’t have to license their derivative works on the same terms). http://creativecommons.org/licenses/by-nc/3.0/
---
......@@ -360,10 +360,16 @@ See "git help gc" for manual housekeeping.