Yanchuan 的个人资料GillBates: I lead, other...照片日志列表更多 工具 帮助

关于Google Buffers序列化,JVM的classpath动态添加,jQuery小技巧,webkit下css3的硬件加速动画

1,最近google发布了一个序列化的库Protocol Buffers,尝试了下,在android下的表现很好。
首先看这个lib的大小
y1pOVck4VUZmLvya7bBxJrxkBss5UiRTpKi924pZuEH7Tyd7X10auP9Q9yVAkIRh9QEVKPkMyMyfiAC2H-r0Ou74VPk5shEWUhu[1] 
然后用官网的json库和google buffer在android上随机测试了一组性能,
下面是json的代码

   1. Item[] itemlist = new Item[10];  
   2. JSONArray items = new JSONArray(new String(buffer.toByteArray()));  
   3. final int max = items.length();  
   4. for (int i=0; i < max; i++){  
   5.     Item item  = new Item();  
   6.     item.title = items.getJSONObject(i).getString("title");  
   7.     item.text  = items.getJSONObject(i).getString("text");  
   8.     item.link  = items.getJSONObject(i).getString("url");  
   9.     item.image = Base64.decode(items.getJSONObject(i).getString("image"));  
  10.     itemlist[i] = item;  
  11. }  

结果:
y1p3qypF4ox7eDAYDggsFodEaV-k6qhP-OFKhdD2SIIYd7mNyC82VozmUhKDDIvMhJJLutx9OPr1Pi1xTAm3W7bKA[1]
明显在android上google buffer是很有优势的,但是这个jar有800k,而json是android sdk自带了已经。

2,关于JVM的动态classpath,很多同学都忽略了,下面的代码可以帮你动态加载lib到classpath里

   1:  URI clientJarUri = DynamicClasspath.class.getProtectionDomain().getCodeSource().getLocation().toURI();
   2:  Method addURL = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] {URL.class});
   3:  addURL.setAccessible(true);
   4:  ClassLoader classLoader = ClassLoader.getSystemClassLoader();
   5:  for( URL jarUrl : classpathUrlsToAdd ){
   6:  addURL.invoke(classLoader, jarUrl);
   7:  }

3,jQuery的一些小技巧
3.1 最快选中父元素 $("#searchBox").closest("div"); 
3.2 Document Ready的另外一种写法

  1. //Instead of
  2. $(document).ready(function() {  
  3. //document ready
  4. });  
  5. //Use
  6. $(function(){  
  7. //document ready
  8. }); 

4,html里做元素的平移动画,传统方法,用timer移动元素的left坐标,但是在iphone的safari里有明显延迟,标准做法是用webkit支持的css来完成变换,这样得到硬件支持,完全无延迟。示例代码:

-webkit-transition: left 250ms ease;
-webkit-transform:translateX(-320px)
 
Digg This

评论 (1)

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。

若要添加评论,请使用您的 Windows Live ID 登录(如果您使用过 Hotmail、Messenger 或 Xbox LIVE,您就拥有 Windows Live ID)。登录


还没有 Windows Live ID 吗?请注册

龚叶琼发表:
......
8 月 21 日

引用通告

此日志的引用通告 URL 是:
http://dreamramon.spaces.live.com/blog/cns!9615FB50FFDBCFD3!4605.trak
引用此项的网络日志